Skip to content

Commit

Permalink
Merge pull request #43 from pa-decarvalho/42-automate-docsthemesmd
Browse files Browse the repository at this point in the history
chore: add update_docs script
  • Loading branch information
pa-decarvalho authored Nov 5, 2024
2 parents d863814 + 617a870 commit 2217b86
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
24 changes: 24 additions & 0 deletions .taskfiles/scripts/templates/themes.md
Original file line number Diff line number Diff line change
@@ -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 -%}
47 changes: 47 additions & 0 deletions .taskfiles/scripts/update_docs.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions .taskfiles/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions docs/themes.md
Original file line number Diff line number Diff line change
@@ -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
}
```
Expand All @@ -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
}
```
Expand All @@ -35,7 +35,7 @@ Example:
```json
{
"file": "assets/asciinema/asciinema_example.cast",
"mkap_theme": "blue",
"mkap_theme": "night",
"auto_play": true
}
```
Expand All @@ -59,3 +59,4 @@ Example:
"auto_play": true
}
```

0 comments on commit 2217b86

Please sign in to comment.