Add geenrated resources to be pre-cached by service worker
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
{{ $searchConfig := i18n "bookSearchConfig" | default "{}" }}
|
{{ $searchConfig := i18n "bookSearchConfig" | default "{}" }}
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
const searchDataURL = '{{ $searchData.RelPermalink }}';
|
const searchDataURL = '{{ partial "docs/links/resource-precache" $searchData }}';
|
||||||
const indexConfig = Object.assign({{ $searchConfig }}, {
|
const indexConfig = Object.assign({{ $searchConfig }}, {
|
||||||
includeScore: true,
|
includeScore: true,
|
||||||
useExtendedSearch: true,
|
useExtendedSearch: true,
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ const pages = [
|
|||||||
{{ range .Site.AllPages -}}
|
{{ range .Site.AllPages -}}
|
||||||
"{{ .RelPermalink }}",
|
"{{ .RelPermalink }}",
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
{{ range $permalink, $ok := site.Store.Get "book-sw-precache" -}}
|
||||||
|
"{{ $permalink }}",
|
||||||
|
{{ end -}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ enableGitInfo = true
|
|||||||
|
|
||||||
# /!\ This is an experimental feature, might be removed or changed at any time
|
# /!\ This is an experimental feature, might be removed or changed at any time
|
||||||
# (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use.
|
# (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use.
|
||||||
BookServiceWorker = true
|
BookServiceWorker = "precache"
|
||||||
|
|
||||||
# /!\ This is an experimental feature, might be removed or changed at any time
|
# /!\ This is an experimental feature, might be removed or changed at any time
|
||||||
# (Optional, experimental, default false) Enables a drop-down menu for translations only if a translation is present.
|
# (Optional, experimental, default false) Enables a drop-down menu for translations only if a translation is present.
|
||||||
|
|||||||
@@ -124,7 +124,8 @@ params:
|
|||||||
|
|
||||||
# /!\ This is an experimental feature, might be removed or changed at any time
|
# /!\ This is an experimental feature, might be removed or changed at any time
|
||||||
# (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use.
|
# (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use.
|
||||||
BookServiceWorker: true
|
# can be false, true or 'precache', precache will try to download all content pages on install.
|
||||||
|
BookServiceWorker: 'precache'
|
||||||
|
|
||||||
# /!\ This is an experimental feature, might be removed or changed at any time
|
# /!\ This is an experimental feature, might be removed or changed at any time
|
||||||
# (Optional, experimental, default false) Enables a drop-down menu for translations only if a translation is present.
|
# (Optional, experimental, default false) Enables a drop-down menu for translations only if a translation is present.
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
{{ "<!--" | safeHTML }}
|
||||||
|
Made with Book Theme
|
||||||
|
https://github.com/alex-shpak/hugo-book
|
||||||
|
{{ "-->" | safeHTML }}
|
||||||
|
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="description" content="{{ default .Summary .Description }}">
|
<meta name="description" content="{{ default .Summary .Description }}">
|
||||||
@@ -24,14 +29,17 @@
|
|||||||
|
|
||||||
<!-- Theme stylesheet, you can customize scss by creating `assets/custom.scss` in your website -->
|
<!-- Theme stylesheet, you can customize scss by creating `assets/custom.scss` in your website -->
|
||||||
{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }}
|
{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }}
|
||||||
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" {{ template "integrity" $styles }}>
|
<link rel="stylesheet" href="{{ partial "docs/links/resource-precache" $styles }}" {{ template "integrity" $styles }}>
|
||||||
|
|
||||||
|
<!-- Search -->
|
||||||
{{- if default true .Site.Params.BookSearch -}}
|
{{- if default true .Site.Params.BookSearch -}}
|
||||||
{{- $searchJSFile := printf "%s.search.js" .Language.Lang }}
|
{{- $searchJSFile := printf "%s.search.js" .Language.Lang }}
|
||||||
{{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify | resources.Fingerprint }}
|
{{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify | resources.Fingerprint }}
|
||||||
<script defer src="{{ "fuse.min.js" | relURL }}"></script>
|
<script defer src="{{ "fuse.min.js" | relURL }}"></script>
|
||||||
<script defer src="{{ $searchJS.RelPermalink }}" {{ template "integrity" $searchJS }}></script>
|
<script defer src="{{ partial "docs/links/resource-precache" $searchJS }}" {{ template "integrity" $searchJS }}></script>
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
|
||||||
|
<!-- Service Worker -->
|
||||||
{{- if .Site.Params.BookServiceWorker -}}
|
{{- if .Site.Params.BookServiceWorker -}}
|
||||||
{{- $swJS := resources.Get "sw-register.js" | resources.ExecuteAsTemplate "sw.js" . | resources.Minify | resources.Fingerprint }}
|
{{- $swJS := resources.Get "sw-register.js" | resources.ExecuteAsTemplate "sw.js" . | resources.Minify | resources.Fingerprint }}
|
||||||
<script defer src="{{ $swJS.RelPermalink }}" {{ template "integrity" $swJS }}></script>
|
<script defer src="{{ $swJS.RelPermalink }}" {{ template "integrity" $swJS }}></script>
|
||||||
@@ -44,11 +52,6 @@
|
|||||||
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
|
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
|
||||||
{{ "<!--" | safeHTML }}
|
|
||||||
Made with Book Theme
|
|
||||||
https://github.com/alex-shpak/hugo-book
|
|
||||||
{{ "-->" | safeHTML }}
|
|
||||||
|
|
||||||
{{- define "integrity" -}}
|
{{- define "integrity" -}}
|
||||||
{{- if (urls.Parse .Permalink).Host -}}
|
{{- if (urls.Parse .Permalink).Host -}}
|
||||||
integrity="{{ .Data.Integrity }}" crossorigin="anonymous"
|
integrity="{{ .Data.Integrity }}" crossorigin="anonymous"
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
{{- site.Store.SetInMap "book-sw-precache" .RelPermalink true -}}
|
||||||
|
{{- return .RelPermalink -}}
|
||||||
Reference in New Issue
Block a user