Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions assets/json/offline-search-index.json
Original file line number Diff line number Diff line change
@@ -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 -}}
10 changes: 3 additions & 7 deletions layouts/partials/search-input.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{{ if or .Site.Params.gcs_engine_id .Site.Params.algolia_docsearch }}
<input type="search" class="form-control td-search-input" placeholder="&#xf002; {{ T "ui_search" }}" aria-label="{{ T "ui_search" }}" autocomplete="off">
{{ 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 -}}
Comment on lines -4 to -10
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change reverts #691. Again, I don't know if this is by mistake or by design, but it seems to be happening a little too often IMHO.

I'm wondering if it is a process issue where folks aren't working from the latest version of docsy and simply cause updates to be lost (reverted) when they commit. It might be worth having a discussion about this, WDYT @LisaFC?

/cc @celestehorgan @nate-double-u

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, #714 is a proposed fix.

{{- /* 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 -}}

<input
type="search"
Expand Down