diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 578dab4..4da9f20 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -12,9 +12,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + + - name: Cahce + uses: actions/cache@v3 with: - node-version: 18 + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- - uses: actions/cache@v3 with: @@ -22,12 +30,38 @@ jobs: key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }} restore-keys: ${{ runner.OS }}-npm-cache- - - run: cd frontend && npm install && npm run build + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Setup rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Build REPL + run: | + cd frontend + npm install && npm run build + + - name: Build book + run: | + cd backend + chmod u+x example/assets/bin/* && cp example/assets/bin/* /usr/local/bin + cargo build --release && mdbook build example + + - name: Merge build assets + run: | + mkdir -p build/example + mv frontend/dest/* build/ + mv backend/example/book/* build/example - name: Deploy to github pages uses: crazy-max/ghaction-github-pages@v3.1.0 with: target_branch: gh-pages - build_dir: frontend/dist + build_dir: build env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 50b5e98..48de0e3 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,3 @@ dist-ssr # Rust related book target -example diff --git a/backend/assets/repl.html b/backend/assets/repl.html index 5fba8e1..82cb92c 100644 --- a/backend/assets/repl.html +++ b/backend/assets/repl.html @@ -1,5 +1,5 @@
- +
{code} diff --git a/backend/example/assets/bin/mdbook b/backend/example/assets/bin/mdbook new file mode 100644 index 0000000..557f9c3 Binary files /dev/null and b/backend/example/assets/bin/mdbook differ diff --git a/backend/example/assets/css/patch.css b/backend/example/assets/css/patch.css new file mode 100644 index 0000000..96e0e5c --- /dev/null +++ b/backend/example/assets/css/patch.css @@ -0,0 +1,14 @@ +/* patch for table */ +table { + width: 100%; +} + +table tr :is(th, td) { + padding-block: 7px; +} + +@media (min-width: 768px) { + table tr :is(th, td) { + padding-block: 10px; + } +} diff --git a/backend/example/book.toml b/backend/example/book.toml new file mode 100644 index 0000000..cf2ecc6 --- /dev/null +++ b/backend/example/book.toml @@ -0,0 +1,50 @@ +[book] +authors = ["MR-Addict"] +language = "en" +multilingual = false +src = "src" +title = "mdbook-repl" + +[rust] +edition = "2021" + +[build] +create-missing = false +use-default-preprocessors = false + +[output.html] +default-theme = "Light" +preferred-dark-theme = "Ayu" +curly-quotes = true +mathjax-support = true +copy-fonts = true +no-section-label = false +git-repository-url = "https://github.com/mr-addict/mdbook-repl" +edit-url-template = "https://github.com/mr-addict/mdbook-repl/edit/main/example/{path}" +additional-css = ["assets/css/patch.css"] + +[output.html.print] +enable = true + +[output.html.fold] +enable = true +level = 1 + +[output.html.playground] +runnable = true +editable = false + +[output.html.search] +enable = true +limit-results = 30 +teaser-word-count = 30 +use-boolean-and = true +boost-title = 2 +boost-hierarchy = 1 +boost-paragraph = 1 +expand = true +heading-split-level = 3 +copy-js = true + +[preprocessor.repl] +command = "target/release/mdbook-repl" diff --git a/backend/example/src/SUMMARY.md b/backend/example/src/SUMMARY.md new file mode 100644 index 0000000..976f211 --- /dev/null +++ b/backend/example/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Intro](./intro.md) diff --git a/backend/example/src/intro.md b/backend/example/src/intro.md new file mode 100644 index 0000000..e2419bd --- /dev/null +++ b/backend/example/src/intro.md @@ -0,0 +1,14 @@ +# Mdbook REPL + +**Python** + +```python +# This is a default python code +import calendar + +yy = 2024 # year +mm = 2 # month + +# display the calendar +print(calendar.month(yy, mm)) +```