From bca2da25076c115e459c9c137914eb83ad21e167 Mon Sep 17 00:00:00 2001 From: MartinSchobben Date: Thu, 15 Aug 2024 14:25:35 +0200 Subject: [PATCH] fix order of toc --- chapters/01_classification.qmd | 2 +- src/eo_datascience/render_sfinx_toc.py | 37 +++++++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/chapters/01_classification.qmd b/chapters/01_classification.qmd index a2c95a2..3cf22f1 100644 --- a/chapters/01_classification.qmd +++ b/chapters/01_classification.qmd @@ -1,5 +1,5 @@ --- -title: Classification +title: Classification of Sentinel-2 imagery subtitle: Finding forests with satelite imagery jupyter: kernelspec: diff --git a/src/eo_datascience/render_sfinx_toc.py b/src/eo_datascience/render_sfinx_toc.py index 6c96600..b4aedea 100644 --- a/src/eo_datascience/render_sfinx_toc.py +++ b/src/eo_datascience/render_sfinx_toc.py @@ -1,19 +1,26 @@ 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 -) +def render_toc(): + p = Path("notebooks").glob('*.ipynb') + files = [x.with_suffix('') for x in p if x.is_file()] + files.sort() + titles = [x.stem.split("_")[-1].title() for x in files] + ls = [dict(caption="Preamble", chapters=[dict(file="notebooks/how-to-cite")])] + for i in range(len(titles)): + ls.append(dict(caption=titles[i], chapters=[dict(file=str(files[i]))])) -with open('_toc.yml', 'w+') as ff: - yaml.dump(toc, ff) + toc = dict( + format="jb-book", + root="README", + parts=ls + ) + + with open('_toc.yml', 'w+') as ff: + yaml.dump(toc, ff) + +def main(): + render_toc() + +if __name__ == '__main__': + main() \ No newline at end of file