From a19f45793c35ace706a31238ec06e541fadde7c6 Mon Sep 17 00:00:00 2001 From: "Y.D.X." <73375426+YDX-2147483647@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:29:23 +0800 Subject: [PATCH] feat: Bot Relates-to: #9 https://github.com/YDX-2147483647/Scholar-Compass-front/commit/77b330814864d9275ba4676265342548e0814d39 --- .github/workflows/build.yml | 32 +++++++++++++++++++++++++++++++- .gitignore | 3 +++ docs/bot.md | 11 +++++++++++ mkdocs.yml | 8 ++++++++ overrides/main.html | 24 ++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 docs/bot.md create mode 100644 overrides/main.html diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f11f80f..973f08f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,8 +25,33 @@ concurrency: cancel-in-progress: false jobs: + compile-bot: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + repository: YDX-2147483647/Scholar-Compass-front + ref: free + - uses: pnpm/action-setup@v3 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + cache-dependency-path: pnpm-lock.yaml + - run: pnpm build + - name: Rename to bot.js + run: | + cd out && mv $(jq '.["src/main.tsx"].file' .vite/manifest.json --raw-output) ../bot.js + - name: Upload bot.js + uses: actions/upload-artifact@v4 + with: + name: bot.js + path: bot.js build: runs-on: ubuntu-latest + needs: compile-bot steps: - uses: actions/checkout@v4 with: @@ -42,7 +67,12 @@ jobs: with: tool: just - run: just bootstrap - - run: MKDOCS_ENABLE_GIT_INTEGRATION=true just build + - name: Download bot.js + uses: actions/download-artifact@v4 + with: + name: bot.js + path: docs/asset + - run: MKDOCS_ENABLE_GIT_INTEGRATION=true MKDOCS_BOT=production just build - uses: actions/upload-pages-artifact@v3 with: path: site/ diff --git a/.gitignore b/.gitignore index ad4a1f1..7fab490 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Generated +/docs/asset/bot.js + # Created by https://www.toptal.com/developers/gitignore/api/python # Edit at https://www.toptal.com/developers/gitignore?templates=python diff --git a/docs/bot.md b/docs/bot.md new file mode 100644 index 0000000..63a467c --- /dev/null +++ b/docs/bot.md @@ -0,0 +1,11 @@ +--- +comments: false +hide: + - navigation + - toc + - footer +--- + +# 机器人 + +
diff --git a/mkdocs.yml b/mkdocs.yml index 288b7fc..e4aded0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -95,3 +95,11 @@ watch: extra_css: - asset/style/extra.css + +extra: + # Whether and where to load scripts + # + # - `development` ⇒ load from Vite dev server http://localhost:5173 + # - `production` ⇒ load from the file `asset/bot.js` + # - Unset or anything else ⇒ disable + bot: !ENV [MKDOCS_BOT, "disable"] diff --git a/overrides/main.html b/overrides/main.html new file mode 100644 index 0000000..8e6b401 --- /dev/null +++ b/overrides/main.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block scripts %} + {{ super() }} + + {# + Bot + + https://vitejs.dev/guide/backend-integration.html + #} + {% if config.extra.bot == "development" %} + + + + {% elif config.extra.bot == "production" %} + + {% endif %} +{% endblock %}