Welcome to mirror list, hosted at ThFree Co, Russian Federation.

list.algolia.json « _default « layouts - github.com/thingsym/hugo-theme-techdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4dda5d4a7110823d3d5dcc9151b7d148a8befbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{{/* Generates a valid Algolia search index */}}
{{- $section := $.Site.GetPage "section" .Section }}
{{- $validVars := $.Param "algolia.vars" | default slice -}}
{{- $validParams := $.Param "algolia.params" | default slice -}}

{{- range $i, $page := .Site.AllPages -}}
  {{- $dot := . -}}
  {{- if or (and ($page.IsDescendant $section) (and (not $page.Draft) (not $page.Params.private))) $section.IsHome -}}
    {{ if $page.File }}
      {{- .Scratch.SetInMap $page.File.Path "objectID" $page.File.UniqueID -}}
    {{- end -}}

    {{- .Scratch.SetInMap "temp" "date" $page.Date.UTC.Unix -}}
    {{ if ne ( $page.PublishDate.Format "2006-01-02" ) "0001-01-01" }}
      {{- .Scratch.SetInMap "temp" "publishdate" $page.PublishDate -}}
    {{- end -}}
    {{ if ne ( $page.Lastmod.Format "2006-01-02" ) "0001-01-01" }}
      {{- .Scratch.SetInMap "temp" "lastmod" $page.Lastmod -}}
    {{- end -}}
    {{- .Scratch.SetInMap "temp" "content" ($page.Plain | truncate 2000) -}}
    {{- .Scratch.SetInMap "temp" "title" $page.Title -}}
    {{- .Scratch.SetInMap "temp" "permalink" $page.Permalink -}}
    {{- .Scratch.SetInMap "temp" "description" $page.Description -}}

    {{/* Include valid page vars */}}
    {{- range $key, $param := (.Scratch.Get "temp") -}}
      {{- if in $validVars $key -}}
        {{ if $page.File }}
          {{- $dot.Scratch.SetInMap $page.File.Path $key $param -}}
        {{- end -}}
      {{- end -}}
    {{- end -}}

    {{/* Include valid page params */}}
    {{- range $key, $param := $page.Params -}}
      {{- if in $validParams $key -}}
        {{ if $page.File }}
         {{- $dot.Scratch.SetInMap $page.File.Path $key $param -}}
        {{- end -}}
      {{- end -}}
    {{- end -}}
    {{ if $page.File }}
      {{- $.Scratch.SetInMap "index" $page.File.Path (.Scratch.Get $page.File.Path) -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

{{- $.Scratch.GetSortedMapValues "index" | jsonify -}}