From 617a8707150fee0ca364944ee91b2c3cd8303965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe-Andr=C3=A9=20De=20Carvalho?= Date: Tue, 5 Nov 2024 12:46:41 +0000 Subject: [PATCH] chore: add update_docs script --- .taskfiles/scripts/templates/themes.md | 24 +++++++++++++ .taskfiles/scripts/update_docs.py | 47 ++++++++++++++++++++++++++ .taskfiles/update.yml | 7 ++++ docs/themes.md | 13 +++---- 4 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 .taskfiles/scripts/templates/themes.md create mode 100644 .taskfiles/scripts/update_docs.py diff --git a/.taskfiles/scripts/templates/themes.md b/.taskfiles/scripts/templates/themes.md new file mode 100644 index 0000000..a2594bb --- /dev/null +++ b/.taskfiles/scripts/templates/themes.md @@ -0,0 +1,24 @@ +# Themes + +{% for theme in themes -%} +## {{ theme|capitalize }} Theme + +```asciinema-player +{ + "file": "assets/asciinema/asciinema_example.cast", + "mkap_theme": "{{ theme }}", + "auto_play": true +} +``` + +Example: + +```json +{ + "file": "assets/asciinema/asciinema_example.cast", + "mkap_theme": "{{ theme }}", + "auto_play": true +} +``` + +{% endfor -%} diff --git a/.taskfiles/scripts/update_docs.py b/.taskfiles/scripts/update_docs.py new file mode 100644 index 0000000..95d77fb --- /dev/null +++ b/.taskfiles/scripts/update_docs.py @@ -0,0 +1,47 @@ +import os +from pathlib import Path +from jinja2 import Environment, FileSystemLoader + + +def generate_theme_documentation(templates_dir: str, output_file: str, doc_template_path: str) -> None: + """ + Generate themes documentation using a Jinja template. + + Args: + templates_dir: Path to the directory containing theme files + output_file: Path to the output file to generate + doc_template_path: Path to the Jinja template + """ + # Get all .html files from the directory + theme_files = [f for f in os.listdir(templates_dir) if f.endswith('.html')] + + # Extract theme names (without .html extension) + themes = sorted([os.path.splitext(f)[0] for f in theme_files]) + + # Configure Jinja + env = Environment( + loader=FileSystemLoader(os.path.dirname(doc_template_path)), + lstrip_blocks=True, + trim_blocks=True, + autoescape=True, + ) + template = env.get_template(os.path.basename(doc_template_path)) + + # Generate content using the template + content = template.render(themes=themes) + + # Create output directory if needed + output_path = Path(output_file) + output_path.parent.mkdir(parents=True, exist_ok=True) + + # Write content to output file + with open(output_file, 'w', encoding='utf-8') as f: + f.write(content) + +if __name__ == "__main__": + # Default paths, adjust as needed + templates_dir = "src/mkdocs_asciinema_player/templates/themes" + doc_template_path = ".taskfiles/scripts/templates/themes.md" + output_file = "docs/themes.md" + + generate_theme_documentation(templates_dir, output_file, doc_template_path) diff --git a/.taskfiles/update.yml b/.taskfiles/update.yml index dd179fe..2c899b2 100644 --- a/.taskfiles/update.yml +++ b/.taskfiles/update.yml @@ -8,7 +8,14 @@ tasks: cmds: - poetry run python .taskfiles/scripts/update_dependencies.py + docs: + desc: Update docs + silent: true + cmds: + - poetry run python .taskfiles/scripts/update_docs.py + all: desc: Run all updates cmds: - task: dependencies + - task: docs diff --git a/docs/themes.md b/docs/themes.md index 6d3e79a..2f7408c 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -1,11 +1,11 @@ # Themes -## Night Theme +## Blue Theme ```asciinema-player { "file": "assets/asciinema/asciinema_example.cast", - "mkap_theme": "night", + "mkap_theme": "blue", "auto_play": true } ``` @@ -15,17 +15,17 @@ Example: ```json { "file": "assets/asciinema/asciinema_example.cast", - "mkap_theme": "night", + "mkap_theme": "blue", "auto_play": true } ``` -## Blue Theme +## Night Theme ```asciinema-player { "file": "assets/asciinema/asciinema_example.cast", - "mkap_theme": "blue", + "mkap_theme": "night", "auto_play": true } ``` @@ -35,7 +35,7 @@ Example: ```json { "file": "assets/asciinema/asciinema_example.cast", - "mkap_theme": "blue", + "mkap_theme": "night", "auto_play": true } ``` @@ -59,3 +59,4 @@ Example: "auto_play": true } ``` +