1、search.json: (我放在了项目根目录下)
2、index.html: (我的博客只需要在首页添加搜索,所以只加在了index)
<!-- Html Elements for Search -->
<div id="search-container">
<input type="text" id="search-input" placeholder="search..." style="padding-left: 5px">
<ul></ul>
<ul id="results-container"></ul>
</div>
<!-- Script pointing to jekyll-search.js -->
<script src="https://www.levyleo.cn/static/js/jekyll-search.js" type="text/javascript"></script>
<script type="text/javascript">
/*jekyll 搜索*/
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: './search.json',
searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
noResultsText: '没有搜索到文章',
limit: 20,
fuzzy: false
})
</script>