From d88a1ad5bade209508e0d6009930b33f04ecbba6 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Fri, 22 Jul 2022 08:46:14 +0200 Subject: [PATCH] Generate a basic favicon dynamically --- .gitignore | 1 + app/templates/layout.html | 1 + app/utils/favicon.py | 22 ++++++++++++++++++++++ docs/static/favicon.ico | Bin 0 -> 326 bytes docs/templates/layout.html | 3 ++- tasks.py | 3 +++ 6 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/utils/favicon.py create mode 100644 docs/static/favicon.ico diff --git a/.gitignore b/.gitignore index 3b3679b..f6eb93d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__/ docs/dist/ requirements.txt app/_version.py +app/static/favicon.ico diff --git a/app/templates/layout.html b/app/templates/layout.html index c2b01bd..de6265f 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -8,6 +8,7 @@ + diff --git a/app/utils/favicon.py b/app/utils/favicon.py new file mode 100644 index 0000000..cc71132 --- /dev/null +++ b/app/utils/favicon.py @@ -0,0 +1,22 @@ +import sass # type: ignore +from PIL import Image +from PIL import ImageColor +from PIL import ImageDraw + + +def _get_primary_color() -> str: + """Small hack to get the theme primary color.""" + compiled = sass.compile( + string=( + "@import 'app/scss/main.scss';\n" + "#favicon-color { color: $primary-color; }" + ) + ) + return compiled[len(compiled) - 11 : -4] + + +def build_favicon() -> None: + """Builds a basic favicon with the theme primary color.""" + im = Image.new("RGB", (32, 32), ImageColor.getrgb(_get_primary_color())) + ImageDraw.Draw(im) + im.save("app/static/favicon.ico") diff --git a/docs/static/favicon.ico b/docs/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..19ac509eeb7fdd80dd69fee64e302a8368f070b0 GIT binary patch literal 326 zcmZQzU}Rus5D;Jh0tJR3AZZ4~5)u%8G?3~5Vg&^VKN(0p2I9^DKX+a(DJ~$B*VDrV zqzz<(00$G0oG>v1WQL@ti(^Q|oa8BMC!{K{8cbYL6>@k*o8nSNhTvBWm##ORRRAht z@O1TaS?83{gvCUV8zjIc=8LXc59BBznYe&0VNsXnVzyo>ldKCX96<~hK?a5#eTGN* z0;X*Qj8*{3D}asuBk^`IkfQ}L`t4aqMg|6!0}fv<1lOqkxXbir)AGlgtM)R3%maaj T!(xA%89qI9V3q`NVXg-N-`!2A literal 0 HcmV?d00001 diff --git a/docs/templates/layout.html b/docs/templates/layout.html index 2bda71d..f398f3c 100644 --- a/docs/templates/layout.html +++ b/docs/templates/layout.html @@ -74,7 +74,8 @@ footer { color: #555; } - + +
diff --git a/tasks.py b/tasks.py index aa8cdf1..1a6006b 100644 --- a/tasks.py +++ b/tasks.py @@ -44,6 +44,9 @@ def lint(ctx): @task def compile_scss(ctx, watch=False): # type: (Context, bool) -> None + from app.utils.favicon import build_favicon + + build_favicon() theme_file = Path("data/_theme.scss") if not theme_file.exists(): theme_file.write_text("// override vars for theming here")