Skip to content

Commit 2c50dae

Browse files
committed
Add file_exists macro to jinja context.
Use file_exists to only render screenshots and logo iif they exist. Add __pycache__ to gitignore.
1 parent b6636d7 commit 2c50dae

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
site
22
venv*
3-
.vscode
3+
.vscode
4+
__pycache__/

docs/themes/screenshots.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
{% set themes = config.extra.themes %}
44
{% for theme in themes %}
5+
{% if file_exists("/docs/site_assets/" ~ page.file.name ~ "/" ~ theme ~ ".png") %}
56
<p align="center">
67
<a href="/site_assets/{{ page.file.name }}/{{ theme }}.png">{{ theme.capitalize() }} Theme<img src="/site_assets/{{ page.file.name }}/{{ theme }}.png"></img>
78
</p>
9+
{% endif %}
810
{% endfor %}

docs/themes/title.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
<h1 align="center"> <img src="/site_assets/{{ page.file.name }}/logo.png" alt="logo" width="30" height="30"> {{ page.file.name.title().replace("-", " ") }} {% if deprecated == True %}(Deprecated){% else %}{% endif %}</h1>
1+
<h1 align="center"> {% if file_exists("/docs/site_assets/" ~ page.file.name ~ "/" ~ "logo.png") %}<img src="/site_assets/{{ page.file.name }}/logo.png" alt="logo" width="30" height="30"> {% endif %}
2+
{{ page.file.name.title().replace("-", " ") }} {% if deprecated == True %}(Deprecated){% else %}{% endif %}</h1>
23

34
Custom [{{ page.file.name.title().replace("-", " ") }}]({{ github_link }}) CSS

main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pathlib import Path
2+
3+
def define_env(env):
4+
@env.macro
5+
def file_exists(filepath: str) -> bool:
6+
if not isinstance(filepath, str):
7+
return False
8+
filepath: Path = Path.cwd() / filepath.lstrip('/')
9+
return filepath.exists()

0 commit comments

Comments
 (0)