From c18a9715b83ef94a56c064edee511162998001cc Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 10 Jan 2021 07:48:34 -0500 Subject: Hotdoc: use template for Commands.md instead of generating the entire file (#8154) * doc: fix hotdoc misuse for dynamically generated content hotdoc has a native include feature for including files inline. Use this to generate one file for each dynamically generated code block, and include that file in Commands.md; see: https://hotdoc.github.io/syntax-extensions.html#smart-file-inclusion-syntax This permits us to move back to using the in-tree version of the hotdoc *.md sources, thus fixing the incorrect inclusion of "builddir/" in the "Edit on github" links which resulted from using copies as the source. Fixes #8061 * doc: call the dummy file a "stamp" as it is a better known term --- tools/regenerate_docs.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'tools') diff --git a/tools/regenerate_docs.py b/tools/regenerate_docs.py index 74a8b0c..b9b994a 100755 --- a/tools/regenerate_docs.py +++ b/tools/regenerate_docs.py @@ -20,7 +20,6 @@ Regenerate markdown docs by using `meson.py` from the root dir ''' import argparse -import jinja2 import os import re import subprocess @@ -108,20 +107,13 @@ def get_commands_data(root_dir: Path) -> T.Dict[str, T.Any]: return cmd_data -def regenerate_commands(root_dir: Path, output_dir: Path) -> None: - with open(root_dir/'docs'/'markdown_dynamic'/'Commands.md') as f: - template = f.read() - +def generate_hotdoc_includes(root_dir: Path, output_dir: Path) -> None: cmd_data = get_commands_data(root_dir) - t = jinja2.Template(template, undefined=jinja2.StrictUndefined, keep_trailing_newline=True) - content = t.render(cmd_help=cmd_data) - - output_file = output_dir/'Commands.md' - with open(output_file, 'w') as f: - f.write(content) - - print(f'`{output_file}` was regenerated') + for cmd, parsed in cmd_data.items(): + for typ in parsed.keys(): + with open(output_dir / (cmd+'_'+typ+'.inc'), 'w') as f: + f.write(parsed[typ]) def regenerate_docs(output_dir: PathLike, dummy_output_file: T.Optional[PathLike]) -> None: @@ -133,7 +125,7 @@ def regenerate_docs(output_dir: PathLike, root_dir = Path(__file__).resolve().parent.parent - regenerate_commands(root_dir, output_dir) + generate_hotdoc_includes(root_dir, output_dir) if dummy_output_file: with open(output_dir/dummy_output_file, 'w') as f: -- cgit v1.1