Add search with Fuse.js
This commit is contained in:
parent
e2417094ed
commit
8633c0c130
13
config.toml
13
config.toml
@ -54,6 +54,16 @@ weight = 50
|
|||||||
identifier = "paper"
|
identifier = "paper"
|
||||||
url = "/paper/"
|
url = "/paper/"
|
||||||
|
|
||||||
|
|
||||||
|
[[menu.main]]
|
||||||
|
name = "Search"
|
||||||
|
weight = 60
|
||||||
|
identifier = "search"
|
||||||
|
url = "/search/"
|
||||||
|
|
||||||
|
[outputs]
|
||||||
|
home = ["HTML", "RSS", "JSON"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
version = "4.x"
|
version = "4.x"
|
||||||
debug = false
|
debug = false
|
||||||
@ -88,6 +98,9 @@ mathjaxEnableSingleDollar = true
|
|||||||
mathjaxEnableAutoNumber = true
|
mathjaxEnableAutoNumber = true
|
||||||
mathjaxUseLocalFiles = false # You should install mathjax in `your-site/static/lib/mathjax`
|
mathjaxUseLocalFiles = false # You should install mathjax in `your-site/static/lib/mathjax`
|
||||||
|
|
||||||
|
# search
|
||||||
|
search = true
|
||||||
|
|
||||||
postMetaInFooter = false
|
postMetaInFooter = false
|
||||||
linkToMarkDown = false
|
linkToMarkDown = false
|
||||||
contentCopyright = ''
|
contentCopyright = ''
|
||||||
|
51
content/search.md
Normal file
51
content/search.md
Normal 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
|
Loading…
Reference in New Issue
Block a user