diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..4bab384 --- /dev/null +++ b/.github/workflows/main.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index 70df1fe..4366672 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ ._* *.iml .DS_Store -local.properties \ No newline at end of file +local.properties + +docs/ \ No newline at end of file diff --git a/generate.py b/generate.py new file mode 100644 index 0000000..93c879e --- /dev/null +++ b/generate.py @@ -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) diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..af32e6d --- /dev/null +++ b/mkdocs.yml @@ -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 diff --git a/overrides/main.html b/overrides/main.html new file mode 100644 index 0000000..a8b2333 --- /dev/null +++ b/overrides/main.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} + +{% block disqus %} + +{% endblock %} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..24d631e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +mkdocs==1.2.3 +mkdocs-material==7.3.6 +pymdown-extensions