mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-14 18:54:27 +00:00
Generate a basic favicon dynamically
This commit is contained in:
parent
edae9a6b62
commit
d88a1ad5ba
6 changed files with 29 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@ __pycache__/
|
||||||
docs/dist/
|
docs/dist/
|
||||||
requirements.txt
|
requirements.txt
|
||||||
app/_version.py
|
app/_version.py
|
||||||
|
app/static/favicon.ico
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<link rel="alternate" title="{{ local_actor.display_name}}'s microblog" type="application/json" href="{{ url_for("json_feed") }}" />
|
<link rel="alternate" title="{{ local_actor.display_name}}'s microblog" type="application/json" href="{{ url_for("json_feed") }}" />
|
||||||
<link rel="alternate" href="{{ url_for("rss_feed") }}" type="application/rss+xml" title="{{ local_actor.display_name}}'s microblog">
|
<link rel="alternate" href="{{ url_for("rss_feed") }}" type="application/rss+xml" title="{{ local_actor.display_name}}'s microblog">
|
||||||
<link rel="alternate" href="{{ url_for("atom_feed") }}" type="application/atom+xml" title="{{ local_actor.display_name}}'s microblog">
|
<link rel="alternate" href="{{ url_for("atom_feed") }}" type="application/atom+xml" title="{{ local_actor.display_name}}'s microblog">
|
||||||
|
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
||||||
<style>
|
<style>
|
||||||
{{ highlight_css }}
|
{{ highlight_css }}
|
||||||
</style>
|
</style>
|
||||||
|
|
22
app/utils/favicon.py
Normal file
22
app/utils/favicon.py
Normal file
|
@ -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")
|
BIN
docs/static/favicon.ico
vendored
Normal file
BIN
docs/static/favicon.ico
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 326 B |
3
docs/templates/layout.html
vendored
3
docs/templates/layout.html
vendored
|
@ -74,7 +74,8 @@ footer {
|
||||||
color: #555;
|
color: #555;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="static/codehilite.css" type="text/css" />
|
<link rel="stylesheet" href="/static/codehilite.css" type="text/css" />
|
||||||
|
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
|
3
tasks.py
3
tasks.py
|
@ -44,6 +44,9 @@ def lint(ctx):
|
||||||
@task
|
@task
|
||||||
def compile_scss(ctx, watch=False):
|
def compile_scss(ctx, watch=False):
|
||||||
# type: (Context, bool) -> None
|
# type: (Context, bool) -> None
|
||||||
|
from app.utils.favicon import build_favicon
|
||||||
|
|
||||||
|
build_favicon()
|
||||||
theme_file = Path("data/_theme.scss")
|
theme_file = Path("data/_theme.scss")
|
||||||
if not theme_file.exists():
|
if not theme_file.exists():
|
||||||
theme_file.write_text("// override vars for theming here")
|
theme_file.write_text("// override vars for theming here")
|
||||||
|
|
Loading…
Reference in a new issue