Add search with Fuse.js

This commit is contained in:
Thomas Dehaeze 2020-04-21 13:25:23 +02:00
parent e2417094ed
commit 8633c0c130
3 changed files with 65 additions and 1 deletions

View File

@ -54,6 +54,16 @@ weight = 50
identifier = "paper"
url = "/paper/"
[[menu.main]]
name = "Search"
weight = 60
identifier = "search"
url = "/search/"
[outputs]
home = ["HTML", "RSS", "JSON"]
[params]
version = "4.x"
debug = false
@ -88,6 +98,9 @@ mathjaxEnableSingleDollar = true
mathjaxEnableAutoNumber = true
mathjaxUseLocalFiles = false # You should install mathjax in `your-site/static/lib/mathjax`
# search
search = true
postMetaInFooter = false
linkToMarkDown = false
contentCopyright = ''

51
content/search.md Normal file
View File

@ -0,0 +1,51 @@
---
title: "Search Results"
sitemap:
priority : 0.1
layout: "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"
]
\```

@ -1 +1 @@
Subproject commit d5f9575a83ff165c5a560b68a49493459ec5f326
Subproject commit 624b3c60e80e9bcccfdadae2da71b47319e3be59