Skip to content

Commit 6897bc5

Browse files
committed
feat(pwa): Refactor pwa versioning
* SW version is now sourced directly from the theme's version. * A build timestamp is appended to this version to create a unique identifier for each build (e.g., `1.0.2-1729382400`). Signed-off-by: Khusika Dhamar Gusti <[email protected]>
1 parent 3657cf5 commit 6897bc5

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

exampleSite/content/posts/theme-documentation-basics/index.en.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ Please open the code block below to view the complete sample configuration :(fa-
216216
# {{< version 1.0.0 >}} whether to enable CSS and JS source mapping
217217
SourceMap = true
218218

219-
# {{< version 1.0.1 >}}PWA config
219+
# {{< version 1.0.3 changed >}}PWA config
220220
[params.pwa]
221221
# whether to enable PWA support
222222
enable = true
223-
# service-worker version
224-
version = "1.0.2"
223+
# {{< version 1.0.3 changed >}}
224+
# The PWA version is now automatically generated based on the theme version and build timestamp.
225+
# version = ""
225226

226227
# {{< version 0.2.0 >}} App icon config
227228
[params.app]

exampleSite/content/posts/theme-documentation-basics/index.fr.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,13 @@ Please open the code block below to view the complete sample configuration :(fa-
221221
# {{< version 1.0.0 >}} whether to enable CSS and JS source mapping
222222
SourceMap = true
223223

224-
# {{< version 1.0.1 >}}PWA config
224+
# {{< version 1.0.3 changed >}}PWA config
225225
[params.pwa]
226226
# whether to enable PWA support
227227
enable = true
228-
# service-worker version
229-
version = "1.0.2"
228+
# {{< version 1.0.3 changed >}}
229+
# The PWA version is now automatically generated based on the theme version and build timestamp.
230+
# version = ""
230231

231232
# {{< version 0.2.0 >}} App icon config
232233
[params.app]

exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,13 @@ hugo
219219
# {{< version 1.0.0 >}} 是否启用 CSS 和 JS 源映射
220220
SourceMap = true
221221

222-
# {{< version 1.0.1 >}}PWA config
222+
# {{< version 1.0.3 changed >}}PWA config
223223
[params.pwa]
224224
# whether to enable PWA support
225225
enable = true
226-
# service-worker version
227-
version = "1.0.2"
226+
# {{< version 1.0.3 changed >}}
227+
# The PWA version is now automatically generated based on the theme version and build timestamp.
228+
# version = ""
228229

229230
# {{< version 0.2.0 >}} 应用图标配置
230231
[params.app]

exampleSite/hugo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,6 @@ ignoreErrors = ["err-missing-comment-accesstoken", "err-missing-oembed-accesstok
575575
# whether to enable PWA support
576576
# 是否要启用 PWA
577577
enable = true
578-
# service-worker version
579-
# service-worker 版本
580-
version = "1.0.2"
581578

582579
# Header config
583580
# 页面头部导航栏配置

layouts/_partials/pwa.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{{- $pwa := .Scratch.Get "pwa" -}}
2+
{{- if $pwa -}}
3+
{{- $version := printf "%s-%d" (.Scratch.Get "version") now.Unix -}}
24
<script>
35
if ('serviceWorker' in navigator) {
46
navigator.serviceWorker
5-
.register('/sw.min.js?version={{ $pwa.version }}', { scope: '/' })
7+
.register('/sw.min.js?version={{ $version }}', { scope: '/' })
68
.then(() => {
79
console.info('{{- .Site.Title -}}\u00A0Service Worker Registered');
810
}, err => console.error('{{- .Site.Title -}}\u00A0Service Worker registration failed: ', err));
@@ -14,3 +16,4 @@
1416
});
1517
}
1618
</script>
19+
{{- end -}}

0 commit comments

Comments
 (0)