mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-09 16:15:16 +00:00
Also, attempt to increase relevancy of search results in general. Close #921
63 lines
2.7 KiB
JSON
63 lines
2.7 KiB
JSON
{{- /* Generate the search index. */ -}}
|
|
{{- $index := slice -}}
|
|
{{- $pages := where .Site.RegularPages "Section" "!=" "home" -}}
|
|
{{- /* Add the index page of docs separately since it's not in RegularPages above. */ -}}
|
|
{{- $pages := $pages | union (where (where .Site.Pages "Kind" "section") "Type" "docs") -}}
|
|
{{- /* Add author pages to index so their bios can be searched. Hide empty `/author/` node. */ -}}
|
|
{{- $pages := $pages | union (where (where $.Site.Pages "Section" "author") "Params.name" "!=" nil) -}}
|
|
|
|
{{- range $pages -}}
|
|
{{- /* Do not index drafts or private pages. */ -}}
|
|
{{- if and (not .Draft) (not .Params.private) -}}
|
|
|
|
{{- /* Generate page description. */ -}}
|
|
{{- $desc := "" -}}
|
|
{{- if .Params.summary -}}
|
|
{{- $desc = .Params.summary -}}
|
|
{{- else if .Params.abstract -}}
|
|
{{- $desc = .Params.abstract -}}
|
|
{{- else -}}
|
|
{{- $desc = .Summary -}}
|
|
{{- end -}}
|
|
|
|
{{- $authors := .Params.authors -}}
|
|
{{- $title := .Title}}
|
|
{{- $rel_permalink := .RelPermalink -}}
|
|
{{- $permalink := .Permalink -}}
|
|
|
|
{{/* Correct the title and URL for author profile pages. */}}
|
|
{{- if eq .Section "author" -}}
|
|
{{- $title = .Params.name -}}
|
|
{{- $dir := path.Base (path.Split .Path).Dir -}}
|
|
{{- with $.Site.GetPage (printf "/authors/%s" (path.Base (path.Split .Path).Dir)) -}}
|
|
{{- $permalink = .Permalink -}}
|
|
{{- $rel_permalink = .RelPermalink -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{/* Include a user's display name rather than username where possible. */}}
|
|
{{- if .Params.authors -}}
|
|
{{- $authorLen := len .Params.authors -}}
|
|
{{- if gt $authorLen 0 -}}
|
|
{{- $authors = slice -}}
|
|
{{- range $k, $v := .Params.authors -}}
|
|
{{- $person_page_path := (printf "/author/%s" (urlize $v)) -}}
|
|
{{- $person_page := $.Site.GetPage $person_page_path -}}
|
|
{{- if $person_page -}}
|
|
{{- $person := $person_page.Params -}}
|
|
{{- $authors = $authors | append $person.name -}}
|
|
{{- else -}}
|
|
{{- $authors = $authors | append ($v | plainify) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Add page to index. */ -}}
|
|
{{- $index = $index | append (dict "objectID" .UniqueID "date" .Date.UTC.Unix "publishdate" .PublishDate "lastmod" .Lastmod.UTC.Unix "expirydate" .ExpiryDate.UTC.Unix "lang" .Lang "permalink" $permalink "relpermalink" $rel_permalink "title" $title "summary" (plainify $desc) "content" .Plain "authors" $authors "kind" .Kind "type" .Type "section" .Section "tags" .Params.Tags "categories" .Params.Categories) -}}
|
|
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $index | jsonify -}}
|