Skip to content

Commit

Permalink
render pythia toc
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchobben committed Jul 19, 2024
1 parent 4f993c9 commit 9d0f170
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jobs:
- name: Commit Files Pythia Book
if: github.ref == 'refs/heads/main'
run: |
python src/render_sfinx_toc.py
cp ./_toc.yml ./pythia/
cp ./notebooks/*.ipynb ./pythia/notebooks/
cd ./pythia
git config --local user.name "$GITHUB_ACTOR"
Expand Down
19 changes: 19 additions & 0 deletions src/render_sfinx_toc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path
import yaml

p = Path("notebooks").glob('*.ipynb')
files = [x.with_suffix('') for x in p if x.is_file()]
titles = [x.stem.split("_")[-1].title() for x in files]
ls = []
for i in range(len(titles)):
ls.append(dict(caption=titles[i], chapters=[dict(file=str(files[i]))]))
ls.append(dict(caption="Preamble", chapters=[dict(file="notebooks/how-to-cite")]))
ls.reverse()
toc = dict(
format="jb-book",
root="README",
parts=ls
)

with open('_toc.yml', 'w+') as ff:
yaml.dump(toc, ff)

0 comments on commit 9d0f170

Please sign in to comment.