Skip to content

Commit

Permalink
ci: build mdbook example
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Addict committed Feb 17, 2024
1 parent e091192 commit ab1125d
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 6 deletions.
42 changes: 38 additions & 4 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,56 @@ 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:
path: "**/node_modules"
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 }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ dist-ssr
# Rust related
book
target
example
2 changes: 1 addition & 1 deletion backend/assets/repl.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="repl" data-id="{id}" data-lang="{lang}">
<iframe src="http://localhost:5173" allow="clipboard-write"></iframe>
<iframe src="https://mr-addict.github.io/mdbook-repl" allow="clipboard-write"></iframe>
</div>

{code}
Binary file added backend/example/assets/bin/mdbook
Binary file not shown.
14 changes: 14 additions & 0 deletions backend/example/assets/css/patch.css
Original file line number Diff line number Diff line change
@@ -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;
}
}
50 changes: 50 additions & 0 deletions backend/example/book.toml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions backend/example/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Summary

- [Intro](./intro.md)
14 changes: 14 additions & 0 deletions backend/example/src/intro.md
Original file line number Diff line number Diff line change
@@ -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))
```

0 comments on commit ab1125d

Please sign in to comment.