From 2c50daed6f624ea45389168753cec292f64b928c Mon Sep 17 00:00:00 2001 From: Marius <24592972+gilbN@users.noreply.github.com> Date: Sat, 25 Oct 2025 13:35:47 +0200 Subject: [PATCH] Add file_exists macro to jinja context. Use file_exists to only render screenshots and logo iif they exist. Add __pycache__ to gitignore. --- .gitignore | 3 ++- docs/themes/screenshots.md | 2 ++ docs/themes/title.md | 3 ++- main.py | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 main.py diff --git a/.gitignore b/.gitignore index c52ef795..25da9d5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ site venv* -.vscode \ No newline at end of file +.vscode +__pycache__/ \ No newline at end of file diff --git a/docs/themes/screenshots.md b/docs/themes/screenshots.md index f0d79140..48521f64 100644 --- a/docs/themes/screenshots.md +++ b/docs/themes/screenshots.md @@ -2,7 +2,9 @@ {% set themes = config.extra.themes %} {% for theme in themes %} +{% if file_exists("/docs/site_assets/" ~ page.file.name ~ "/" ~ theme ~ ".png") %}

{{ theme.capitalize() }} Theme

+{% endif %} {% endfor %} \ No newline at end of file diff --git a/docs/themes/title.md b/docs/themes/title.md index 8dbd9d8a..1ba9746f 100644 --- a/docs/themes/title.md +++ b/docs/themes/title.md @@ -1,3 +1,4 @@ -

logo {{ page.file.name.title().replace("-", " ") }} {% if deprecated == True %}(Deprecated){% else %}{% endif %}

+

{% if file_exists("/docs/site_assets/" ~ page.file.name ~ "/" ~ "logo.png") %}logo {% endif %} +{{ page.file.name.title().replace("-", " ") }} {% if deprecated == True %}(Deprecated){% else %}{% endif %}

Custom [{{ page.file.name.title().replace("-", " ") }}]({{ github_link }}) CSS \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 00000000..4d32ffc5 --- /dev/null +++ b/main.py @@ -0,0 +1,9 @@ +from pathlib import Path + +def define_env(env): + @env.macro + def file_exists(filepath: str) -> bool: + if not isinstance(filepath, str): + return False + filepath: Path = Path.cwd() / filepath.lstrip('/') + return filepath.exists()