【注意】最后更新于 November 26, 2017,文中内容可能已过时,请谨慎使用。
Hugo本地搜索
配置
修改 config.toml
,
1
2
| [outputs]
home = ["HTML", "RSS", "JSON"]
|
修改 theme
下 partials/index.json
1
2
3
4
5
6
7
8
9
10
11
12
| /// YOUR_TEMPLATE/partials/index.json
[
{{ range $index, $element := (where .Site.RegularPages "Type" "post") }}
{
"title" : {{ jsonify .Title }},
"date" : {{- jsonify .Date.Format ( or .Site.Params.dateFormat "2006, Jan 02" ) -}},
"url" : {{ jsonify .Permalink }},
"content": {{ jsonify .Summary }},
"tag" : {{ jsonify .Params.Tag }}
}{{if not (eq $index (sub (len (where .Site.RegularPages "Type" "post")) 1 )) }} , {{end}}
{{ end }}
]
|
YOUR_TEMPLATE/partials/_default/search.html
1
2
3
4
5
6
7
| <main id="searchLayout" class="container">
<input id="search-input" type="text" placeholder="Type something and hit enter"/>
<p id="search-info"></p>
<div id="search-result"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.0.5/fuse.min.js"></script>
<script src="search.js"></script>
</main>
|