diff --git a/content/posts/search.md b/content/posts/search.md new file mode 100644 index 0000000..0f038c1 --- /dev/null +++ b/content/posts/search.md @@ -0,0 +1,52 @@ +--- +title: "Search Results" +sitemap: + priority : 0.1 +layout: "search" +url: search +--- + + +This file exists solely to respond to /search URL with the related `search` layout template. + +No content shown here is rendered, all content is based in the template layouts/page/search.html + +Setting a very low sitemap priority will tell search engines this is not important content. + +This implementation uses Fusejs, jquery and mark.js + + +## Initial setup + +Search depends on additional output content type of JSON in config.toml +\``` +[outputs] + home = ["HTML", "JSON"] +\``` + +## Searching additional fileds + +To search additional fields defined in front matter, you must add it in 2 places. + +### Edit layouts/_default/index.JSON +This exposes the values in /index.json +i.e. add `category` +\``` +... + "contents":{{ .Content | plainify | jsonify }} + {{ if .Params.tags }}, + "tags":{{ .Params.tags | jsonify }}{{end}}, + "categories" : {{ .Params.categories | jsonify }}, +... +\``` + +### Edit fuse.js options to Search +`static/js/search.js` +\``` +keys: [ + "title", + "contents", + "tags", + "categories" +] +\``` diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 670c99c..52c5095 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -32,6 +32,14 @@ languages: languageName: 中文 weight: 8 +# At least HTML and JSON are required for the main HTML content and +# client-side JavaScript search +outputs: + home: + - HTML + - RSS + - JSON + # Force a locale to be use, really useful to develop the application ! Should be commented in production, the "weight" should rocks. # DefaultContentLanguage: fr diff --git a/layouts/_default/index.json b/layouts/_default/index.json new file mode 100644 index 0000000..c29397c --- /dev/null +++ b/layouts/_default/index.json @@ -0,0 +1,5 @@ +{{- $.Scratch.Add "index" slice -}} +{{- range .Site.RegularPages -}} + {{- $.Scratch.Add "index" (dict "title" .Title "hero" (partial "helpers/get-hero.html" .) "date" (.Date.Format "January 2, 2006") "summary" .Summary "tags" .Params.tags "categories" .Params.categories "contents" .Plain "permalink" .Permalink) -}} +{{- end -}} +{{- $.Scratch.Get "index" | jsonify -}} diff --git a/layouts/_default/list.html b/layouts/_default/list.html index f6e79cb..ae014d1 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -16,7 +16,9 @@