Skip to content

Commit

Permalink
fix(init): Properly set PWA on production environment
Browse files Browse the repository at this point in the history
Fixes broken commit on 8d52d26
  • Loading branch information
Khusika Dhamar Gusti committed Aug 5, 2021
1 parent fc18207 commit 2e6eacb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- partial "init.html" . -}}

{{- $params := .Scratch.Get "params" -}}
{{- $pwa := .Scratch.Get "pwa" -}}
{{- $offline := $params.offline -}}

<!DOCTYPE html>
Expand Down Expand Up @@ -42,11 +43,9 @@
{{- if ne .Site.Params.footer.enable false -}}
{{- partial "footer.html" . -}}
{{- end -}}
{{- if eq hugo.Environment "production" -}}
{{- with (eq $.Site.Params.pwa.enable "true") -}}
{{- if and (eq hugo.Environment "production") ($pwa.enable) -}}
{{- partial "pwa.html" . -}}
{{- end -}}
{{- end -}}
</footer>
</div>

Expand Down
5 changes: 2 additions & 3 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{- $cdn := .Scratch.Get "cdn" | default dict -}}
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
{{- $config := (.Scratch.Get "this").config -}}
{{- $pwa := .Scratch.Get "pwa" -}}

{{- /* Font Awesome */ -}}
{{- if $params.cdnfontawesome -}}
Expand Down Expand Up @@ -175,11 +176,9 @@
{{- end -}}
{{- end -}}

{{- if eq hugo.Environment "production" -}}
{{- with (eq $.Site.Params.pwa.enable "true") -}}
{{- if and (eq hugo.Environment "production") ($pwa.enable) -}}
{{- dict "Source" "sw.js" "Minify" true "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}
{{- end -}}

{{- /* Cookie Consent */ -}}
{{- if .Site.Params.cookieconsent | and .Site.Params.cookieconsent.enable -}}
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/init.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{{- end -}}
{{- end -}}
{{- .Scratch.Set "cdn" $cdn -}}
{{- .Scratch.Set "pwa" .Site.Params.pwa -}}
{{- .Scratch.Set "fingerprint" .Site.Params.fingerprint -}}
{{- .Scratch.Set "analytics" .Site.Params.analytics -}}
{{- .Scratch.Set "comment" $params.comment -}}
Expand Down
3 changes: 2 additions & 1 deletion layouts/partials/pwa.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{- $pwa := .Scratch.Get "pwa" -}}
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/sw.min.js?version={{.Site.Params.pwa.version}}', { scope: '/' })
.register('/sw.min.js?version={{ $pwa.version }}', { scope: '/' })
.then(() => {
console.info('{{- .Site.Title -}}\u00A0Service Worker Registered');
}, err => console.error('{{- .Site.Title -}}\u00A0Service Worker registration failed: ', err));
Expand Down

0 comments on commit 2e6eacb

Please sign in to comment.