Skip to content
Merged
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
13 changes: 12 additions & 1 deletion .github/workflows/docs-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,26 @@ jobs:
print(issue)
PY

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install mdbook-mermaid
env:
MDBOOK_MERMAID_VERSION: '0.17.0'
run: cargo install mdbook-mermaid --locked --version "${MDBOOK_MERMAID_VERSION}"

- name: Install mdBook
env:
MDBOOK_VERSION: '0.4.36'
MDBOOK_VERSION: '0.5.2'
run: |
curl -fsSL "https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz" -o /tmp/mdbook.tar.gz
tar -xzf /tmp/mdbook.tar.gz -C /tmp
sudo install /tmp/mdbook /usr/local/bin/mdbook
mdbook --version

- name: Install mdbook-mermaid assets
run: mdbook-mermaid install book

- name: Build mdBook
run: mdbook build book

Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,30 @@ concurrency:
group: pages
cancel-in-progress: false

env:
MDBOOK_VERSION: "0.5.2"
MDBOOK_MERMAID_VERSION: "0.17.0"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install mdbook-mermaid
run: cargo install mdbook-mermaid --locked --version "${MDBOOK_MERMAID_VERSION}"

- name: Install mdbook-mermaid assets
run: mdbook-mermaid install book

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v2
with:
mdbook-version: latest
mdbook-version: ${{ env.MDBOOK_VERSION }}

- name: Setup Pages
uses: actions/configure-pages@v5
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ docs/generated/

# mdBook build output
book/book/
book/mermaid.min.js

# Local git worktrees created for vendored submodules
3rd-party/*.worktrees/
Expand Down
6 changes: 6 additions & 0 deletions book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ authors = ["Agent"]
language = "zh-cn"
src = "src"
title = "Nano Agent Documentation"

[preprocessor.mermaid]
command = "mdbook-mermaid"

[output.html]
additional-js = ["mermaid.min.js", "mermaid-init.js"]
33 changes: 33 additions & 0 deletions book/mermaid-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

(() => {
const darkThemes = ['ayu', 'navy', 'coal'];
const lightThemes = ['light', 'rust'];

const classList = document.getElementsByTagName('html')[0].classList;

const lastThemeWasLight = !darkThemes.some((theme) => classList.contains(theme));

const theme = lastThemeWasLight ? 'default' : 'dark';
mermaid.initialize({ startOnLoad: true, theme });

// Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page

for (const darkTheme of darkThemes) {
document.getElementById(darkTheme)?.addEventListener('click', () => {
if (lastThemeWasLight) {
window.location.reload();
}
});
}

for (const lightTheme of lightThemes) {
document.getElementById(lightTheme)?.addEventListener('click', () => {
if (!lastThemeWasLight) {
window.location.reload();
}
});
}
})();