Simple-Jekyll-Search
A JavaScript library to add search functionality to any Jekyll blog. Simple-Jekyll-Search
使用方法
-
使用
bower
安装js
文件bower install --save simple-jekyll-search
-
在
blog
的根路径添加search.json
,内容如下--- layout: null --- [ {% for post in site.posts %} { "title" : "{{ post.title | escape }}", "category" : "{{ post.category }}", "tags" : "{{ post.tags | join: ', ' }}", "url" : "{{ site.baseurl }}{{ post.url }}", "date" : "{{ post.date }}" } {% unless forloop.last %},{% endunless %} {% endfor %} ]
-
在搜索页面添加输入框与引入
js
<!-- HTML elements for search --> <div id="search-container"> <input type="text" id="search-input" placeholder="search..."> <ul id="results-container"></ul> </div> <!-- script pointing to jekyll-search.js --> <script src="/simple-jekyll-search.min.js"></script> <script> SimpleJekyllSearch({ searchInput: document.getElementById('search-input'), resultsContainer: document.getElementById('results-container'), json: '/search.json' }) </script>