From d01237d0037bd688fe4acf46f51071ea04a16856 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 11 Nov 2018 01:19:37 +0000 Subject: [PATCH] fix(search): add index page of docs to search index Allows to search content on the main page of docs/tutorials/courses. Previously, all docs pages except the main page were indexed. --- layouts/index.json | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/layouts/index.json b/layouts/index.json index 5ade36c6..83369d07 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -1,16 +1,28 @@ -{{/* Generate the search index. */}} -{{- $scr := $.Scratch -}} -{{- $scr.Add "index" slice -}} -{{- range (where .Site.RegularPages "Section" "!=" "home") -}} +{{- /* Generate the search index. */ -}} +{{- $index := slice -}} +{{- $pages := where .Site.RegularPages "Section" "!=" "home" -}} +{{- $pages := $pages | union (where (where .Site.Pages "Kind" "section") "Type" "docs") -}} +{{- /* TODO: Add author pages to index so their bios can be searched. */ -}} +{{- /* $pages := $pages | union (where (where .Site.Pages "Kind" "taxonomy") "taxonomyTerm" "author") */ -}} + +{{- range $pages -}} + {{- /* Do not index drafts or private pages. */ -}} {{- if and (not .Draft) (not .Params.private) -}} - {{- if .Params.abstract -}} - {{- $scr.Set "summary" .Params.abstract -}} - {{- else if .Params.summary -}} - {{- $scr.Set "summary" .Params.summary -}} + + {{- /* Generate page description. */ -}} + {{- $desc := "" -}} + {{- if .Params.summary -}} + {{- $desc = .Params.summary -}} + {{- else if .Params.abstract -}} + {{- $desc = .Params.abstract -}} {{- else -}} - {{- $scr.Set "summary" .Summary -}} + {{- $desc = .Summary -}} {{- end -}} - {{- $scr.Add "index" (dict "objectID" .UniqueID "date" .Date.UTC.Unix "publishdate" .PublishDate "lastmod" .Lastmod.UTC.Unix "expirydate" .ExpiryDate.UTC.Unix "lang" .Lang "permalink" .Permalink "relpermalink" .RelPermalink "title" .Title "summary" (plainify ($scr.Get "summary")) "content" .Plain "authors" .Params.Authors "kind" .Kind "type" .Type "section" .Section "tags" .Params.Tags "categories" .Params.Categories)}} + + {{- /* 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" .RelPermalink "title" .Title "summary" (plainify $desc) "content" .Plain "authors" .Params.Authors "kind" .Kind "type" .Type "section" .Section "tags" .Params.Tags "categories" .Params.Categories) -}} + {{- end -}} {{- end -}} -{{- $scr.Get "index" | jsonify -}} + +{{- $index | jsonify -}}