From 1985aed2e6db1282eb48f65b60dad930c05b1caa Mon Sep 17 00:00:00 2001 From: Flo Greistorfer Date: Tue, 9 Jul 2024 08:56:49 +0200 Subject: [PATCH] improvements to webmanifest --- builder.py | 15 +++++++-------- templates/index.html.j2 | 2 +- templates/manifest.json.j2 | 4 +++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/builder.py b/builder.py index d1feb78..2ea4230 100755 --- a/builder.py +++ b/builder.py @@ -31,7 +31,7 @@ FAVICON_PATH = ".static/favicon.ico" GLOBAL_CSS_PATH = ".static/global.css" DEFAULT_THEME_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), "themes", "default.css") DEFAULT_AUTHOR = "Author" -VERSION = "1.9.0" +VERSION = "1.9.1" RAW_EXTENSIONS = [".3fr", ".ari", ".arw", ".bay", ".braw", ".crw", ".cr2", ".cr3", ".cap", ".data", ".dcs", ".dcr", ".dng", ".drf", ".eip", ".erf", ".fff", ".gpr", ".iiq", ".k25", ".kdc", ".mdc", ".mef", ".mos", ".mrw", ".nef", ".nrw", ".obm", ".orf", ".pef", ".ptx", ".pxn", ".r3d", ".raf", ".raw", ".rwl", ".rw2", ".rwz", ".sr2", ".srf", ".srw", ".tif", ".tiff", ".x3f"] IMG_EXTENSIONS = [".jpg", ".jpeg"] EXCLUDES = [".lock", "index.html", "manifest.json", ".sizelist.json", ".thumbnails", ".static"] @@ -128,7 +128,7 @@ def webmanifest(_args: Args) -> None: files = os.listdir(os.path.join(STATIC_FILES_DIR, "icons")) if svgsupport and any(file.endswith(".svg") for file in files): svg = [file for file in files if file.endswith(".svg")][0] - icons.append({"src": f"/icons/svg", "type": "image/svg+xml", "sizes": "any"}) + icons.append({"src": f"{_args.web_root_url}/icons/{svg}", "type": "image/svg+xml", "sizes": "any"}) for size in ICON_SIZES: tmpimg = BytesIO() sizes = size.split("x") @@ -142,19 +142,18 @@ def webmanifest(_args: Args) -> None: ) with Image.open(tmpimg) as iconfile: iconfile.save(iconpath, format="PNG") - icons.append({"src": iconpath, "sizes": size, "type": "image/png"}) + icons.append({"src": f"{_args.web_root_url}/.static/icons/{os.path.splitext(svg)[0] + "-" + size + ".png"}", "sizes": size, "type": "image/png"}) else: for icon in os.listdir(os.path.join(STATIC_FILES_DIR, "icons")): if not icon.endswith(".png"): continue with Image.open(os.path.join(STATIC_FILES_DIR, "icons", icon)) as iconfile: iconsize = f"{iconfile.size[0]}x{iconfile.size[1]}" - icons.append({"src": f".static/pwa/icons/{icon}", "sizes": iconsize, "type": "image/png"}) + icons.append({"src": f"{_args.web_root_url}/.static/icons/{icon}", "sizes": iconsize, "type": "image/png"}) if len(icons) == 0: print("No icons found in the static/icons folder!") return - site_id = urllib.parse.quote(_args.web_root_url.replace("https://", "").replace("http://", "").replace("/", "")) with open(os.path.join(_args.root_directory, ".static", "theme.css")) as f: content = f.read() background_color = ( @@ -163,12 +162,12 @@ def webmanifest(_args: Args) -> None: theme_color = ( content.replace(".navbar{", "navbar {").split(".navbar {")[1].split("}")[0].split("background-color:")[1].split(";")[0].strip() ) - with open(os.path.join(_args.root_directory, "manifest.json"), "w", encoding="utf-8") as f: + with open(os.path.join(_args.root_directory, ".static", "manifest.json"), "w", encoding="utf-8") as f: manifest = env.get_template("manifest.json.j2") content = manifest.render( - name=_args.site_title, + name=_args.web_root_url.replace("https://", "").replace("http://", "").replace("/", ""), + short_name=_args.site_title, icons=icons, - id=site_id, background_color=background_color, theme_color=theme_color, ) diff --git a/templates/index.html.j2 b/templates/index.html.j2 index 11da4fe..71a585b 100644 --- a/templates/index.html.j2 +++ b/templates/index.html.j2 @@ -6,7 +6,7 @@ {{ title }} {%- if webmanifest %} - + {%- endif %} diff --git a/templates/manifest.json.j2 b/templates/manifest.json.j2 index 7279980..745ce50 100644 --- a/templates/manifest.json.j2 +++ b/templates/manifest.json.j2 @@ -1,5 +1,7 @@ { "name": "{{ name }}", + "short_name": "{{ short_name }}", + "description": "{{ name }} - A static web gallery - made with StaticGalleryBuilder (https://github.com/greflm13/StaticGalleryBuilder)", "icons": [ {% for icon in icons -%} { @@ -10,7 +12,7 @@ }{% if not loop.last %},{% endif %} {%- endfor %} ], - "id": "{{ id }}", + "id": "/", "start_url": "/", "background_color": "{{ background_color }}", "display": "standalone",