zzossig 5 éve
szülő
commit
9d0c83fafd

+ 11 - 1
exampleSite/config/_default/config.toml

@@ -33,7 +33,17 @@ disableKinds = ["taxonomyTerm"]
     startLevel = 2
 
 [outputs]
-  home = ["HTML", "RSS", "JSON"]
+  page = ["HTML", "SearchIndex"]
+  home = ["HTML", "RSS", "SearchIndex"]
+  section = ["HTML", "RSS", "SearchIndex"]
+  taxonomy = ["HTML", "RSS", "SearchIndex"]
+
+[outputFormats]
+  [outputFormats.SearchIndex]
+    mediaType = "application/json"
+    baseName = "index"
+    isPlainText = true
+    notAlternative = true
 
 [taxonomies]
   tag = "tags"

+ 7 - 0
layouts/_default/list.searchindex.json

@@ -0,0 +1,7 @@
+{{- $.Scratch.Add "searchindex" slice -}}
+{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
+  {{ with $element.Plain }}
+    {{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
+  {{ end }}
+{{- end -}}
+{{- $.Scratch.Get "searchindex" | jsonify -}}

+ 7 - 0
layouts/_default/single.searchindex.json

@@ -0,0 +1,7 @@
+{{- $.Scratch.Add "searchindex" slice -}}
+{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
+  {{ with $element.Plain }}
+    {{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
+  {{ end }}
+{{- end -}}
+{{- $.Scratch.Get "searchindex" | jsonify -}}

+ 7 - 0
layouts/_default/terms.searchindex.json

@@ -0,0 +1,7 @@
+{{- $.Scratch.Add "searchindex" slice -}}
+{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
+  {{ with $element.Plain }}
+    {{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
+  {{ end }}
+{{- end -}}
+{{- $.Scratch.Get "searchindex" | jsonify -}}

+ 6 - 11
layouts/index.json

@@ -1,12 +1,7 @@
-[{{ range $index, $page := .Site.Pages }}
-{{- if ne $page.Type "json" -}}
-{{- if and $index (gt $index 0) -}},{{- end }}
-{
-	"uri": "{{ $page.Permalink }}",
-	"title": "{{ htmlEscape $page.Title}}",
-	"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
-	"description": "{{ htmlEscape .Description}}",
-	"content": {{$page.Plain | jsonify}}
-}
+{{- $.Scratch.Add "searchindex" slice -}}
+{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
+  {{ with $element.Plain }}
+    {{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
+  {{ end }}
 {{- end -}}
-{{- end -}}]
+{{- $.Scratch.Get "searchindex" | jsonify -}}