From 77b5ecd7ec21392ba8d1beaf936837311c033898 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 4 Oct 2021 23:00:17 +0900 Subject: [PATCH 1/2] Suppress blank lines from offline-search-index.json output --- assets/json/offline-search-index.json | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/assets/json/offline-search-index.json b/assets/json/offline-search-index.json index b3e21c5543..0396a0876c 100644 --- a/assets/json/offline-search-index.json +++ b/assets/json/offline-search-index.json @@ -1,7 +1,18 @@ {{- $.Scratch.Add "offline-search-index" slice -}} {{- range where .Site.AllPages ".Params.exclude_search" "!=" true -}} -{{/* We have to apply `htmlUnescape` again after `truncate` because `truncate` applies `html.EscapeString` if the argument is not HTML. */}} -{{/* Indvidual taxonomies can be added in the next line by add '"taxonomy-name" (.Params.taxonomy-name | default "")' to the dict (as seen for categories and tags). */}} -{{- $.Scratch.Add "offline-search-index" (dict "ref" .RelPermalink "title" .Title "categories" (.Params.categories | default "") "tags" (.Params.tags | default "") "description" (.Description | default "") "body" (.Plain | htmlUnescape) "excerpt" ((.Description | default .Plain) | htmlUnescape | truncate (.Site.Params.offlineSearchSummaryLength | default 70) | htmlUnescape)) -}} +{{- /* We have to apply `htmlUnescape` again after `truncate` because `truncate` applies `html.EscapeString` if the argument is not HTML. */ -}} +{{- /* Indvidual taxonomies can be added in the next line by add '"taxonomy-name" (.Params.taxonomy-name | default "")' to the dict (as seen for categories and tags). */ -}} +{{- $.Scratch.Add + "offline-search-index" + (dict + "ref" .RelPermalink + "title" .Title + "categories" (.Params.categories | default "") + "tags" (.Params.tags | default "") + "description" (.Description | default "") + "body" (.Plain | htmlUnescape) + "excerpt" ((.Description | default .Plain) | htmlUnescape | truncate (.Site.Params.offlineSearchSummaryLength | default 70) | htmlUnescape) + ) +-}} {{- end -}} {{- $.Scratch.Get "offline-search-index" | jsonify -}} From 76cbc3d62d62f0cee19d4ebb5c3269cf39b40771 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 4 Oct 2021 23:15:36 +0900 Subject: [PATCH 2/2] Fix EXECUTE-AS-TEMPLATE error with offline-search-index.json --- layouts/partials/search-input.html | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/layouts/partials/search-input.html b/layouts/partials/search-input.html index a811e14a7d..2f22f96bac 100644 --- a/layouts/partials/search-input.html +++ b/layouts/partials/search-input.html @@ -1,13 +1,9 @@ {{ if or .Site.Params.gcs_engine_id .Site.Params.algolia_docsearch }} {{ else if .Site.Params.offlineSearch }} -{{ $offlineSearchIndex := resources.Get "json/offline-search-index.json" | resources.ExecuteAsTemplate "offline-search-index.json" . }} -{{ $offlineSearchLink := $offlineSearchIndex.RelPermalink -}} -{{ if hugo.IsProduction -}} -{{/* Use `md5` as finger print hash function to shorten file name to avoid `file name too long` error. */}} -{{ $offlineSearchIndexFingerprint := $offlineSearchIndex | resources.Fingerprint "md5" }} -{{ $offlineSearchLink = $offlineSearchIndexFingerprint.RelPermalink -}} -{{ end -}} +{{- /* Use `md5` as finger print hash function to shorten file name to avoid `file name too long` error. */ -}} +{{- $offlineSearchIndex := resources.Get "json/offline-search-index.json" | resources.ExecuteAsTemplate "offline-search-index.json" . | fingerprint "md5" -}} +{{- $offlineSearchLink := $offlineSearchIndex.RelPermalink -}}