Skip to content

Commit

Permalink
feat: Bot
Browse files Browse the repository at this point in the history
  • Loading branch information
YDX-2147483647 committed Mar 27, 2024
1 parent 5295bf0 commit a19f457
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
32 changes: 31 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 11 additions & 0 deletions docs/bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
comments: false
hide:
- navigation
- toc
- footer
---

# 机器人

<div id="bot-root"></div>
8 changes: 8 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
24 changes: 24 additions & 0 deletions overrides/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "base.html" %}

{% block scripts %}
{{ super() }}

{#
Bot

https://vitejs.dev/guide/backend-integration.html
#}
{% if config.extra.bot == "development" %}
<script type="module">
import RefreshRuntime from 'http://localhost:5173/@react-refresh';
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => type => type;
window.__vite_plugin_react_preamble_installed__ = true;
</script>
<script type="module" src="http://localhost:5173/@vite/client"></script>
<script type="module" src="http://localhost:5173/src/main.tsx"></script>
{% elif config.extra.bot == "production" %}
<script type="module" src="{{ config.site_url }}asset/bot.js"></script>
{% endif %}
{% endblock %}

0 comments on commit a19f457

Please sign in to comment.