Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 利用 mkdocs 在线浏览表情包 #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Update dir
run: python generate.py

- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@nomaterial
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
._*
*.iml
.DS_Store
local.properties
local.properties

docs/
65 changes: 65 additions & 0 deletions generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import shutil
from urllib.parse import quote

EXCLUDE_DIRS = ['.git', 'docs', '.vscode', 'overrides', '.github', 'script']
README_MD = ['README.md', 'readme.md', 'index.md']
INDEX_FILE = 'index.md'

IMAGE_EXTS = ['jpg', 'png', 'svg', 'jpeg', 'gif', 'webp']
IMAGE_URL_PREFIX = 'https://github.com/beiyuouo/hainanu-course-comments/blob/main/'
BIN_URL_PREFIX = 'https://github.com/beiyuouo/hainanu-course-comments/raw/main/'


def list_image(course: str):
imagelist_text = f'# {os.path.basename(course)}\n'

for root, dirs, files in os.walk(course):
files.sort()
readme_path = '{}/{}'.format(root, INDEX_FILE)
level = root.replace(course, '').count(os.sep)
for f in files:
if f.split('.')[-1].lower() in IMAGE_EXTS:
imagelist_text += '![]({}){{ width="200" }}\n'.format(os.path.join(f))
return imagelist_text, readme_path


def generate_md(course: str, filelist_texts: str, readme_path: str, topic: str):
final_texts = ['\n\n'.encode(), filelist_texts.encode()]
topic_path = os.path.join('docs', topic)
if not os.path.isdir(topic_path):
os.mkdir(topic_path)
with open(os.path.join(topic_path, '{}.md'.format(course)), 'wb') as file:
file.writelines(final_texts)


if __name__ == '__main__':
if os.path.exists('docs'):
shutil.rmtree('docs')
if not os.path.isdir('docs'):
os.mkdir('docs')

topics = list(
filter(lambda x: os.path.isdir(x) and (x not in EXCLUDE_DIRS),
os.listdir('.'))) # list topics

for topic in topics:
topic_path = os.path.join('.', topic)
target_path = os.path.join('docs', topic)

if os.path.exists(target_path):
shutil.rmtree(target_path)
shutil.copytree(topic_path, target_path)

topic_path = os.path.join(".", topic)
imagelist_text, readme_path = list_image(topic_path)
generate_md('index', imagelist_text, readme_path, topic)

with open('README.md', 'rb') as file:
mainreadme_lines = file.readlines()

with open('docs/index.md', 'wb') as file:
file.writelines(mainreadme_lines)
30 changes: 30 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
site_name: EmojiPackage

theme:
name: material
custom_dir: overrides
features:
- navigation.indexes

repo_url: https://github.com/getActivity/EmojiPackage

markdown_extensions:
- def_list
- pymdownx.tasklist:
custom_checkbox: true
- attr_list
- md_in_html
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg

plugins:
- search:
lang:
- en
- zh

extra:
analytics:
provider: google
property: UA-145083103-1
17 changes: 17 additions & 0 deletions overrides/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "base.html" %}

{% block disqus %}
<script src="https://giscus.app/client.js"
data-repo="beiyuouo/mkdocs-emoticon-gallery"
data-repo-id="R_kgDOGSn1gw"
data-category="General"
data-category-id="DIC_kwDOGSn1g84B_n2h"
data-mapping="pathname"
data-reactions-enabled="1"
data-emit-metadata="0"
data-theme="light"
data-lang="en"
crossorigin="anonymous"
async>
</script>
{% endblock %}
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mkdocs==1.2.3
mkdocs-material==7.3.6
pymdown-extensions