diff --git a/backend/scripts/generate_pages_config.py b/backend/scripts/generate_pages_config.py new file mode 100644 index 00000000..c4837743 --- /dev/null +++ b/backend/scripts/generate_pages_config.py @@ -0,0 +1,35 @@ +import argparse +import json +import re +from pathlib import Path + +from transcribee_backend.config import PageConfig + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("input_dir", type=Path) + parser.add_argument("output", type=Path) + parser.add_argument("--footer-pages", nargs="+", default=[]) + args = parser.parse_args() + + pages = {} + for file in args.input_dir.glob("*.md"): + name = file.stem + with open(file) as f: + text = f.read() + match = re.search(r"^#\s+(.*?)$", text, re.MULTILINE) + if match: + name = match.group(1) + pages[file.stem] = {"name": name, "text": text} + footer_position = None + try: + footer_position = args.footer_pages.index(file.stem) + except ValueError: + pass + + pages[file.stem] = PageConfig( + name=name, footer_position=footer_position, text=text + ) + + with open(args.output, "w") as f: + json.dump({k: dict(v) for k, v in pages.items()}, f) diff --git a/doc/development_setup.md b/doc/development_setup.md index 8a2ead27..70ad6535 100644 --- a/doc/development_setup.md +++ b/doc/development_setup.md @@ -53,6 +53,24 @@ If you do more development on transcribee, you may wish to do the following thin - Install the [`pre-commit`](https://pre-commit.com/) hook so that your changes are automatically linted before you commit them. Run: `pre-commit install` +## Add pages + +`transcribee` contains a minimal page system. +To add pages, add a `pages.json` in `backend/data`. +You can generate such a `pages.json` from a directory of markdown-files using the following command in the `backend/`-folder. + +```shell +pdm run generate_pages_json PATH/TO/MARKDOWN/FOLDER data/pages.json +``` + +You can select which pages should be always shown in the footer using the `--footer-pages` option to the script. For example if you wanted the content of `page1.md` and `page2.md` to be shown in the footer, run + +``` +pdm run generate_pages_json PATH/TO/MARKDOWN/FOLDER data/pages.json --footer-pages page1 page2 +``` + +The link text is automatically generated from the first first-level heading in the document. + ## More! There are more specific instructions in the respective readme files of the