Skip to content

Commit f07e938

Browse files
authored
quarto (#95)
1 parent da20a08 commit f07e938

File tree

8 files changed

+89
-61
lines changed

8 files changed

+89
-61
lines changed

.github/ci.jl

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,32 @@ using SHA
88
using Literate, JSON
99
end
1010

11-
# Strip SVG output from a Jupyter notebook
12-
@everywhere function strip_svg(nbpath)
11+
# Post-process Jupyter notebook
12+
@everywhere function postprocess(nbpath)
1313
oldfilesize = filesize(nbpath)
1414
nb = open(JSON.parse, nbpath, "r")
1515
for cell in nb["cells"]
1616
!haskey(cell, "outputs") && continue
1717
for output in cell["outputs"]
1818
!haskey(output, "data") && continue
1919
datadict = output["data"]
20+
## Remove SVG to reduce file size
2021
if haskey(datadict, "image/png") || haskey(datadict, "image/jpeg")
2122
delete!(datadict, "text/html")
2223
delete!(datadict, "image/svg+xml")
2324
end
25+
## Process LaTeX output, wrap in an array if needed
26+
if haskey(datadict, "text/latex")
27+
latexcode = datadict["text/latex"]
28+
if (! (latexcode isa Vector))
29+
datadict["text/latex"] = [latexcode]
30+
end
31+
end
2432
end
2533
end
2634
rm(nbpath; force=true)
27-
write(nbpath, JSON.json(nb, 1))
28-
@info "Stripped SVG in $(nbpath). The original size is $(Base.format_bytes(oldfilesize)). The new size is $(Base.format_bytes(filesize(nbpath)))."
35+
write(nbpath, JSON.json(nb, 2))
36+
@info "$(nbpath) is processed. The original size is $(Base.format_bytes(oldfilesize)). The new size is $(Base.format_bytes(filesize(nbpath)))."
2937
return nbpath
3038
end
3139

@@ -41,7 +49,7 @@ function clean_cache(cachedir)
4149
if !isfile(nb) && !isfile(lit)
4250
cachepath = joinpath(root, fn)
4351
@info "Notebook $(nb) or $(lit) not found. Removing $(cachepath) SHA and notebook."
44-
rm(cachepath * ".sha")
52+
rm(cachepath * ".sha"; force=true)
4553
rm(cachepath * ".ipynb"; force=true)
4654
end
4755
end
@@ -104,30 +112,30 @@ function list_notebooks(basedir, cachedir)
104112
end
105113

106114
# Run a Literate notebook
107-
@everywhere function run_literate(file, cachedir; rmsvg=true)
115+
@everywhere function run_literate(file, cachedir; dopostproc=true)
108116
outpath = joinpath(abspath(pwd()), cachedir, dirname(file))
109117
mkpath(outpath)
110118
ipynb = Literate.notebook(file, dirname(file); mdstrings=true, execute=true)
111-
rmsvg && strip_svg(ipynb)
119+
dopostproc && postprocess(ipynb)
112120
cp(ipynb, joinpath(outpath, basename(ipynb)); force=true)
113121
return ipynb
114122
end
115123

116124
function main(;
117125
basedir=get(ENV, "DOCDIR", "docs"),
118126
cachedir=get(ENV, "NBCACHE", ".cache"),
119-
rmsvg=true)
127+
dopostproc=true)
120128

121129
mkpath(cachedir)
122130
clean_cache(cachedir)
123131
litnbs = list_notebooks(basedir, cachedir)
124132

125133
if !isempty(litnbs)
126-
# Execute literate notebooks in worker process(es)
134+
## Execute literate notebooks in worker process(es)
127135
ts_lit = pmap(litnbs; on_error=identity) do nb
128-
@elapsed run_literate(nb, cachedir; rmsvg)
136+
@elapsed run_literate(nb, cachedir; dopostproc)
129137
end
130-
rmprocs(workers()) # Remove worker processes to release some memory
138+
rmprocs(workers()) ## Remove worker processes to release some memory
131139
failed = false
132140
for (nb, t) in zip(litnbs, ts_lit)
133141
if t isa ErrorException
@@ -137,9 +145,9 @@ function main(;
137145
end
138146

139147
if failed
140-
error("Please check literate notebook error(s).")
148+
error("Please check error(s).")
141149
else
142-
# Print execution result
150+
## Print execution result
143151
Tables.table([litnbs ts_lit]; header=["Notebook", "Elapsed (s)"]) |> markdown_table(String) |> print
144152
end
145153
end

.github/workflows/ci.yml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Build notebooks and publish
22

33
on:
44
workflow_dispatch:
@@ -39,19 +39,18 @@ jobs:
3939
- name: Read Julia version
4040
id: julia-version
4141
run: python -c 'import tomllib; from pathlib import Path; print("value=", tomllib.loads(Path("Manifest.toml").read_text())["julia_version"], sep="")' >> "$GITHUB_OUTPUT"
42-
- name: Get hashes
42+
- name: Get environment hash
4343
id: hash
4444
run: |
4545
echo "value=${{ hashFiles('Project.toml', 'Manifest.toml', 'src/**') }}" >> "$GITHUB_OUTPUT"
46-
echo "nb=${{ hashFiles('docs/**/*.jl', 'docs/**/*.ipynb') }}" >> "$GITHUB_OUTPUT"
4746
- name: Cache executed notebooks
4847
uses: actions/cache@v5
4948
id: cache-nb
5049
with:
5150
path: |
5251
${{ env.NBCACHE }}/**/*.ipynb
5352
${{ env.NBCACHE }}/**/*.sha
54-
key: notebook-${{ steps.hash.outputs.value }}-${{ steps.hash.outputs.nb }}
53+
key: notebook-${{ steps.hash.outputs.value }}-${{ hashFiles('docs/**') }}
5554
restore-keys: |
5655
notebook-${{ steps.hash.outputs.value }}-
5756
- name: Setup Julia
@@ -89,31 +88,27 @@ jobs:
8988
if: ${{ steps.cache-nb.outputs.cache-hit != 'true' }}
9089
run: julia --project=@. --color=yes -p ${{ env.LITERATE_PROC }} .github/ci.jl
9190
- name: Copy back built notebooks
92-
run: cp --verbose -rf ${{ env.NBCACHE }}/docs/* docs/
93-
- name: Setup NodeJS
94-
uses: actions/setup-node@v6
95-
with:
96-
node-version: 'lts/*'
97-
- name: Build website
98-
env:
99-
BASE_URL: /${{ github.event.repository.name }}
10091
run: |
101-
npm install -g "jupyter-book"
102-
jupyter-book build --html --strict
92+
cp --verbose -rf ${{ env.NBCACHE }}/docs/* docs/
93+
find docs/ -type f -name "*.jl" -delete
94+
- name: Setup Quarto
95+
if: ${{ runner.environment == 'github-hosted' }}
96+
uses: quarto-dev/quarto-actions/setup@v2
97+
- name: Render Quarto Project
98+
run: quarto render docs/
10399
- name: Upload pages artifact
104-
if: ${{ github.ref == 'refs/heads/main' }}
105100
uses: actions/upload-pages-artifact@v4
101+
if: ${{ github.ref == 'refs/heads/main' }}
106102
with:
107-
path: './_build/html'
103+
path: docs/_site/
108104

109-
# Deployment job
110105
deploy:
111-
name: Deploy to GitHub pages and Notebook branch
106+
name: Deploy to GitHub pages
112107
needs: CI
113-
if: ${{ github.ref == 'refs/heads/main' }}
108+
if: ${{ github.ref == 'refs/heads/main'}}
114109
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
115110
permissions:
116-
pages: write # to deploy to Pages
111+
pages: write # to deploy to Pages
117112
id-token: write # to verify the deployment originates from an appropriate source
118113
environment:
119114
name: github-pages

.github/workflows/clear-pr-cache.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ on:
66

77
jobs:
88
cleanup:
9-
runs-on: ubuntu-slim
109
permissions:
1110
actions: write
11+
runs-on: ubuntu-slim
1212
steps:
1313
- name: Cleanup
1414
run: |

.github/workflows/linkcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
with:
5252
fail: false
5353
failIfEmpty: false
54-
args: '--accept 200,204,429 --verbose --no-progress --cache --max-cache-age 1d "docs/**/*.md" "docs/**/*.jl"'
54+
args: '--accept 200,204,429 --verbose --no-progress --cache --max-cache-age 1d "docs/**/*.md" "docs/**/*.qmd" "docs/**/*.jl"'
5555
env:
5656
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5757
- name: Create Issue From File

docs/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
3+
*.html.md

docs/_quarto.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# https://quarto.org/docs/projects/quarto-projects.html
2+
project:
3+
type: website
4+
output-dir: _site
5+
6+
# https://quarto.org/docs/websites/
7+
website:
8+
title: CaMKII model
9+
page-navigation: true
10+
bread-crumbs: true
11+
back-to-top-navigation: true
12+
reader-mode: true
13+
repo-url: https://github.com/ntumitolab/ecme-rirr-dox/
14+
site-url: https://ntumitolab.github.io/ecme-rirr-dox/
15+
search:
16+
show-item-context: true
17+
type: overlay
18+
# https://quarto.org/docs/websites/website-navigation.html
19+
navbar:
20+
search: true
21+
tools:
22+
- icon: github
23+
href: https://github.com/ntumitolab/ecme-rirr-dox/
24+
sidebar:
25+
title: false
26+
style: floating
27+
collapse-level: 2
28+
align: left
29+
contents:
30+
- index.qmd
31+
- auto: "*.ipynb"
32+
33+
# bibliography: references.bib
34+
35+
# https://quarto.org/docs/output-formats/html-basics.html
36+
format:
37+
html:
38+
respect-user-color-scheme: true
39+
toc: true
40+
theme: simplex
41+
code-copy: true
42+
code-overflow: wrap
43+
grid:
44+
sidebar-width: 300px
45+
body-width: 1000px
46+
margin-width: 350px
47+
# keep-md: true
48+
# css: styles.css
File renamed without changes.

myst.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)