index.json 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. {{- /* Generate the search index. */ -}}
  2. {{- $index := slice -}}
  3. {{- $pages := site.RegularPages -}}
  4. {{- /* Add the index page of docs separately since it's not in RegularPages above. */ -}}
  5. {{- $pages := $pages | union (where (where site.Pages "Kind" "section") "Type" "docs") -}}
  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.name" "!=" nil) -}}
  8. {{- range $pages -}}
  9. {{- /* Do not index drafts or private pages. */ -}}
  10. {{- if and (not .Draft) (not .Params.private) -}}
  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 "author" -}}
  26. {{- $title = .Params.name -}}
  27. {{- $dir := path.Base (path.Split .Path).Dir -}}
  28. {{- with site.GetPage (printf "/authors/%s" (path.Base (path.Split .Path).Dir)) -}}
  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 "/author/%s" (urlize $v)) -}}
  40. {{- $person_page := site.GetPage $person_page_path -}}
  41. {{- if $person_page -}}
  42. {{- $person := $person_page.Params -}}
  43. {{- $authors = $authors | append $person.name -}}
  44. {{- else -}}
  45. {{- $authors = $authors | append ($v | plainify) -}}
  46. {{- end -}}
  47. {{- end -}}
  48. {{- end -}}
  49. {{- end -}}
  50. {{- end -}}
  51. {{- /* Add page to index. */ -}}
  52. {{- $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) -}}
  53. {{- end -}}
  54. {{- end -}}
  55. {{- $index | jsonify -}}