Przeglądaj źródła

feat: dynamically generate manifest

Adds name, lang, theme_color and background_color.

Removes 32px icon and adds 512px icon based on latest Google best
practices.
George Cushen 6 lat temu
rodzic
commit
0011592861

+ 8 - 1
exampleSite/config/_default/config.toml

@@ -40,9 +40,16 @@ footnotereturnlinkcontents = "<sup>^</sup>"
 ignoreFiles = ["\\.ipynb$", ".ipynb_checkpoints$", "\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"]
 
 [outputs]
-  home = [ "HTML", "RSS", "JSON" ]
+  home = [ "HTML", "RSS", "JSON", "WebAppManifest" ]
   section = [ "HTML", "RSS" ]
 
+[mediaTypes."application/manifest+json"]
+  suffixes = ["webmanifest"]
+
+[outputFormats.WebAppManifest]
+  mediaType = "application/manifest+json"
+  rel = "manifest"
+
 # Configure BlackFriday Markdown rendering.
 #   See: https://gohugo.io/getting-started/configuration/#configure-blackfriday
 [blackfriday]

+ 18 - 0
layouts/index.webmanifest

@@ -0,0 +1,18 @@
+{{- $scr := .Scratch -}}
+{
+  "name": "{{site.Title}}",
+  "lang": "{{site.LanguageCode}}",
+  "theme_color": "{{ $scr.Get "primary" }}",
+  "background_color": "{{ $scr.Get "primary" }}",
+  "icons": [{
+    "src": "img/icon-192.png",
+    "sizes": "192x192",
+    "type": "image/png"
+    }{{- if (fileExists "static/img/icon-512.png") -}}, {
+    "src": "img/icon-512.png",
+    "sizes": "512x512",
+    "type": "image/png"
+     }{{end}}],
+  "display": "standalone",
+  "start_url": "./?utm_source=web_app_manifest"
+}

+ 4 - 1
layouts/partials/site_head.html

@@ -138,7 +138,10 @@
   <link rel="alternate" href="{{.RelPermalink}}" type="application/rss+xml" title="{{site.Title}}">
   {{ end }}
 
-  <link rel="manifest" href="{{ "site.webmanifest" | relURL }}">
+  {{ range .AlternativeOutputFormats }}
+  <link rel="{{.Rel}}" type="{{.MediaType.Type}}" href="{{.RelPermalink | safeURL}}">
+  {{ end }}
+
   <link rel="icon" type="image/png" href="{{ "/img/icon.png" | relURL }}">
   <link rel="apple-touch-icon" type="image/png" href="{{ "/img/icon-192.png" | relURL }}">
 

+ 0 - 13
static/site.webmanifest

@@ -1,13 +0,0 @@
-{
-    "icons": [{
-      "src": "img/icon.png",
-      "sizes": "32x32",
-      "type": "image/png"
-    },{
-        "src": "img/icon-192.png",
-        "sizes": "192x192",
-        "type": "image/png"
-    }],
-    "display": "standalone",
-    "start_url": "./?utm_source=web_app_manifest"
-}