From 405024989cf09eb4d4370dcda57fdf355ba2c464 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Mon, 13 Jul 2026 16:50:10 +0800 Subject: [PATCH] fix(assets): fix sw-update-notification display and PWA guard conditions - Change sw-toast default from `display: flex` to `display: none` with proper CSS discrete transition - Add `display: flex` in `.visible` state and `allow-discrete` transition for display property - Restore production-only guard for SW notification and webmanifest templates - Fix PWA config enable to always be true when template is rendered - Fix extra space in head/index.html conditional --- assets/scss/widgets/_sw-toast.scss | 4 +++- layouts/_partials/base/assets.html | 2 +- layouts/_partials/base/head/index.html | 2 +- layouts/_partials/base/widgets.html | 2 +- layouts/_partials/init/index.html | 2 +- layouts/home.manifest.webmanifest | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/assets/scss/widgets/_sw-toast.scss b/assets/scss/widgets/_sw-toast.scss index e5197cbc..9f07832d 100644 --- a/assets/scss/widgets/_sw-toast.scss +++ b/assets/scss/widgets/_sw-toast.scss @@ -5,7 +5,7 @@ position: fixed; inset-inline-end: 1.5rem; bottom: 1.5rem; - display: flex; + display: none; align-items: center; gap: 0.75rem 1rem; padding: 0.625rem 1rem; @@ -18,11 +18,13 @@ translate: 0 1rem; opacity: 0; transition: + display 0.3s allow-discrete, translate 0.3s, opacity 0.3s; @include z-index(fixed); &.visible { + display: flex; translate: 0 0; opacity: 1; } diff --git a/layouts/_partials/base/assets.html b/layouts/_partials/base/assets.html index 47c75a4a..a2f2a1aa 100644 --- a/layouts/_partials/base/assets.html +++ b/layouts/_partials/base/assets.html @@ -300,7 +300,7 @@ {{- $swBuildCtx := dict "mainCSSURL" $mainCSS.RelPermalink "mainJSURL" $mainJS.RelPermalink "offlineURL" $offlineURL "relURL" (relURL "") "version" (hugo.Store.Get "version") "Page" . -}} {{- $serviceWorker := resources.Get "js/service-worker.template.js" | resources.ExecuteAsTemplate "js/service-worker.template.js" $swBuildCtx -}} {{- $serviceWorker = dict "Resource" $serviceWorker "Build" (dict "targetPath" "sw.js") "Fingerprint" $fingerprint | partial "function/js-build.html" -}} - {{- $config = dict "PWA" (dict "enable" .Site.Params.app.pwa "serviceWorkerURL" $serviceWorker.RelPermalink) | merge $config -}} + {{- $config = dict "PWA" (dict "enable" true "serviceWorkerURL" $serviceWorker.RelPermalink) | merge $config -}} {{- end -}} {{- /* Auto Bookmark */ -}} diff --git a/layouts/_partials/base/head/index.html b/layouts/_partials/base/head/index.html index 3e363d9f..9774a4c1 100644 --- a/layouts/_partials/base/head/index.html +++ b/layouts/_partials/base/head/index.html @@ -98,7 +98,7 @@ {{- /* Alternative output formats (Atom, RSS, manifest etc.) */ -}} {{- range .AlternativeOutputFormats -}} - {{- if (eq .Name "manifest") | and (not $.Site.Params.app.pwa) -}} + {{- if (eq .Name "manifest") | and (not $.Site.Params.app.pwa) -}} {{- continue -}} {{- end -}} diff --git a/layouts/_partials/base/widgets.html b/layouts/_partials/base/widgets.html index 24ead078..50d71d03 100644 --- a/layouts/_partials/base/widgets.html +++ b/layouts/_partials/base/widgets.html @@ -129,7 +129,7 @@ {{- end -}} {{- /* Service Worker Update Notification */ -}} - {{- if .Site.Params.app.pwa -}} + {{- if not hugo.IsServer | and hugo.IsProduction | and .Site.Params.app.pwa -}}
{{ T "serviceWorker.updateTitle" }}
diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 6e37c6fa..557ec2c4 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v1.0.0-mriu2jcf" -}} +{{- hugo.Store.Set "version" "v1.0.0-mrizf1fk" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/home.manifest.webmanifest b/layouts/home.manifest.webmanifest index b0b1c678..278e1939 100644 --- a/layouts/home.manifest.webmanifest +++ b/layouts/home.manifest.webmanifest @@ -1,4 +1,4 @@ -{{- if .Site.Params.app.pwa -}} +{{- if not hugo.IsServer | and hugo.IsProduction | and .Site.Params.app.pwa -}} {{- $name := .Site.Params.app.name | default .Site.Title -}} {{- $shortName := .Site.Params.app.short_name | default $name -}} {{- $startURL := relURL "/" -}}