index.json 2.7 KB

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