From 9d0f17025b962b7a0304ea54cb97febaf55ccbe1 Mon Sep 17 00:00:00 2001 From: Martin Schobben Date: Fri, 19 Jul 2024 11:38:36 +0200 Subject: [PATCH] render pythia toc --- .github/workflows/publish.yaml | 2 ++ src/render_sfinx_toc.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/render_sfinx_toc.py diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 8b3f3e3..8d8a195 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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" diff --git a/src/render_sfinx_toc.py b/src/render_sfinx_toc.py new file mode 100644 index 0000000..7c34ae2 --- /dev/null +++ b/src/render_sfinx_toc.py @@ -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) \ No newline at end of file