From 9d0c83fafd779bc3f8098c59664d8c93e6fed420 Mon Sep 17 00:00:00 2001 From: zzossig Date: Thu, 6 Feb 2020 19:04:23 +0900 Subject: search redesign --- exampleSite/config/_default/config.toml | 12 +++++++++++- layouts/_default/list.searchindex.json | 7 +++++++ layouts/_default/single.searchindex.json | 7 +++++++ layouts/_default/terms.searchindex.json | 7 +++++++ layouts/index.json | 17 ++++++----------- 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 layouts/_default/list.searchindex.json create mode 100644 layouts/_default/single.searchindex.json create mode 100644 layouts/_default/terms.searchindex.json diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml index 509898c..a34be73 100644 --- a/exampleSite/config/_default/config.toml +++ b/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" diff --git a/layouts/_default/list.searchindex.json b/layouts/_default/list.searchindex.json new file mode 100644 index 0000000..b29edc3 --- /dev/null +++ b/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 -}} \ No newline at end of file diff --git a/layouts/_default/single.searchindex.json b/layouts/_default/single.searchindex.json new file mode 100644 index 0000000..b29edc3 --- /dev/null +++ b/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 -}} \ No newline at end of file diff --git a/layouts/_default/terms.searchindex.json b/layouts/_default/terms.searchindex.json new file mode 100644 index 0000000..b29edc3 --- /dev/null +++ b/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 -}} \ No newline at end of file diff --git a/layouts/index.json b/layouts/index.json index 367f3b3..0a96038 100644 --- a/layouts/index.json +++ b/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 -}}] \ No newline at end of file +{{- $.Scratch.Get "searchindex" | jsonify -}} \ No newline at end of file -- cgit v1.2.3