From 407c5d72df789dfbd8af37a1f1d59d17755954ff Mon Sep 17 00:00:00 2001 From: vimux Date: Wed, 28 Aug 2019 10:26:30 -0400 Subject: [PATCH] Web Manifest: don't require .Site.Params.Manifest Before, `.Site.Params.Manifest` was required to activate Web App Manifest. Now, it's optional. Still, `.Site.Params.Manifest` highly recommended. * Don't require .Site.Params.Manifest * Order Web App Manifest properties by required type (except icons) * Add default value to startUrl param [`/`] * README.md: enhance Web App Manifest configuration section * README.md: add table with Web App Manifest default values in Binario --- README.md | 26 ++++++++++++++++++++++---- layouts/_default/baseof.html | 4 ++-- layouts/index.manifest.json | 8 +++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e0a14b2..e197633 100644 --- a/README.md +++ b/README.md @@ -183,11 +183,11 @@ googleAnalytics = "" # Enable Google Analytics by entering your tracking id name = "Binario" shortName = "Binario" display = "browser" + startUrl = "/" backgroundColor = "#2a2a2a" themeColor = "#1b1b1b" description = "Responsive card-based & code-light Hugo theme" orientation = "portrait" - startUrl = "/" scope = "/" [outputFormats] @@ -301,8 +301,8 @@ Stack Overflow, Mastodon, Medium site info like name, description, icons, etc. This file tells the browser about your web application and how it should behave when "installed" (as PWA) on the users mobile device or desktop. -To activate Web App Manifest you need to define `MANIFEST` custom output format & specify `[Params.Manifest]` parameters -in your site config file. +To activate Web App Manifest, define `MANIFEST` as custom output format and include this for `home` Kind attribute in +your site config file. Here's how to make it. First of all, you should define `MANIFEST` custom output format [`config.toml`]: @@ -322,7 +322,25 @@ Then, include `MANIFEST` output format for `home` Kind attribute [`config.toml`] home = ["HTML", "RSS", "MANIFEST"] ``` -After that, you can specify `[Params.Manifest]` parameters. +After that, Web App Manifest file will be generated. Still, it's better to specify `[Params.Manifest]` params to make +sure that everything works as expected. + +| Web App Manifest Property | `.Site.Params.Manifest` Key | Default Value | Type | +| ------------------------- | --------------------------- | ------------- | ----------- | +| name | name | `.Site.Title` | required | +| short_name | shortName | `.Site.Title` | required | +| display | display | `browser` | required | +| start_url | startUrl | `/` | required | +| background_color | backgroundColor | `#2a2a2a` | recommended | +| theme_color | themeColor | `#1b1b1b` | recommended | +| description | description | | recommended | +| orientation | orientation | | recommended | +| scope | scope | | recommended | +| icons\* | | | required | + +\* You can't customize manifest icons through config params, only replacing `icons/192.png` and `icons/512.png` files. + +--- *To verify that your manifest file is configured properly and works well, run Hugo server and open Chrome DevTools (Press F12 in Chrome) → Application → Manifest* diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 6577dd7..07ffe01 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -26,8 +26,8 @@ {{- with .OutputFormats.Get "rss" }} {{ printf `` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }} {{- end }} - {{- if and (.Site.Params.Manifest) ((.Site.GetPage "home").OutputFormats.Get "manifest") -}} - + {{- with ((.Site.GetPage "home").OutputFormats.Get "manifest") }} + {{- end }} {{- if not .Site.IsServer }} {{ template "_internal/google_analytics_async.html" . }} diff --git a/layouts/index.manifest.json b/layouts/index.manifest.json index ba519f2..ffbd6ef 100644 --- a/layouts/index.manifest.json +++ b/layouts/index.manifest.json @@ -1,7 +1,8 @@ { - "name": "{{ if .Site.Params.Manifest.name }}{{ .Site.Params.Manifest.name }}{{ else }}{{ .Site.Title }}{{ end }}", - "short_name": "{{ if .Site.Params.Manifest.shortName }}{{ .Site.Params.Manifest.shortName }}{{ else }}{{ .Site.Title }}{{ end }}", + "name": "{{ .Site.Params.Manifest.name | default .Site.Title }}", + "short_name": "{{ .Site.Params.Manifest.shortName | default .Site.Title }}", "display": "{{ .Site.Params.Manifest.display | default "browser" }}", + "start_url": "{{ .Site.Params.Manifest.startUrl | default "/" }}", "background_color": "{{ .Site.Params.Manifest.backgroundColor | default "#2a2a2a" }}", "theme_color": "{{ .Site.Params.Manifest.themeColor | default "#1b1b1b" }}", {{- with .Site.Params.Manifest.description }} @@ -10,9 +11,6 @@ {{- with .Site.Params.Manifest.orientation }} "orientation": "{{ . }}", {{- end }} - {{- with .Site.Params.Manifest.startUrl }} - "start_url": "{{ . }}", - {{- end }} {{- with .Site.Params.Manifest.scope }} "scope": "{{ . }}", {{- end }}