index.json 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {{- /* Generate the search index. */ -}}
  2. {{- $index := slice -}}
  3. {{- $pages := site.RegularPages -}}
  4. {{- /* Add the index page of multi-page content separately since it's not in RegularPages above. */ -}}
  5. {{- $pages := $pages | union (where (where site.Pages "Kind" "section") "Type" "book") -}}
  6. {{- /* Add author pages to index so their bios can be searched. Hide empty `/authors/` node. */ -}}
  7. {{- $pages := $pages | union (where (where site.Pages "Section" "authors") "Params.superuser" "!=" nil) -}}
  8. {{- range $pages -}}
  9. {{- /* Do not index drafts or private pages. */ -}}
  10. {{- if and (not .Draft) (not .Params.private) | and (ne .Params.searchable false) -}}
  11. {{- /* Generate page description. */ -}}
  12. {{- $desc := "" -}}
  13. {{- if .Params.summary -}}
  14. {{- $desc = .Params.summary -}}
  15. {{- else if .Params.abstract -}}
  16. {{- $desc = .Params.abstract -}}
  17. {{- else -}}
  18. {{- $desc = .Summary -}}
  19. {{- end -}}
  20. {{- $authors := .Params.authors -}}
  21. {{- $title := .Title}}
  22. {{- $rel_permalink := .RelPermalink -}}
  23. {{- $permalink := .Permalink -}}
  24. {{/* Correct the title and URL for author profile pages. */}}
  25. {{- if eq .Section "authors" -}}
  26. {{- $username := path.Base (path.Split .Path).Dir -}}
  27. {{- with site.GetPage (printf "/authors/%s" $username) -}}
  28. {{- $permalink = .Permalink -}}
  29. {{- $rel_permalink = .RelPermalink -}}
  30. {{- end -}}
  31. {{- else -}}
  32. {{/* Include a user's display name rather than username where possible. */}}
  33. {{- if .Params.authors -}}
  34. {{- $authorLen := len .Params.authors -}}
  35. {{- if gt $authorLen 0 -}}
  36. {{- $authors = slice -}}
  37. {{- range $k, $v := .Params.authors -}}
  38. {{- $person_page_path := (printf "/authors/%s" (urlize $v)) -}}
  39. {{- $person_page := site.GetPage $person_page_path -}}
  40. {{- if and $person_page $person_page.File -}}
  41. {{- $authors = $authors | append $person_page.Title -}}
  42. {{- else -}}
  43. {{- $authors = $authors | append ($v | plainify) -}}
  44. {{- end -}}
  45. {{- end -}}
  46. {{- end -}}
  47. {{- end -}}
  48. {{- end -}}
  49. {{- /* Add page to index. */ -}}
  50. {{- $index = $index | append (dict "objectID" .File.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 | htmlUnescape) "content" (.Plain | htmlUnescape | truncate 5000) "authors" $authors "kind" .Kind "type" .Type "section" .Section "tags" .Params.Tags "categories" .Params.Categories) -}}
  51. {{- end -}}
  52. {{- end -}}
  53. {{- $index | jsonify -}}