Preview: https://kytrun.com, or download this project, place example/
directory in the themes path of Gridea, and run Gridea yourself.
It is only suitable for Gridea theme developers with a foundation in front-end programming; themes using grinda-search can be viewed here .
├── assets
│ └── media
│ └── gridea-search
│ └── result-template.ejs - 搜索结果列表模板
│ └── ejs.min.js - 模板渲染引擎
│ └── fuse.basic.min.js - 模糊搜索
│ └── gridea-search.js - 功能入口
└── templates
├── api.ejs - 输出整站 API
└── search.ejs - 搜索页面
The template that outputs the JSON format API. In order to shorten the network transmission time as much as possible, some attributes are initially annotated. You can cancel the corresponding annotations as needed.
Public template, add a search box at the appropriate location for reference by other pages:
< form id =" gridea-search-form " action =" <%= themeConfig.domain %>/search/ " >
< input name =" q " />
</ form >
The existing part cannot be modified, other attributes such as class or style can be added.
The search page can be modified based on other pages, and then add search result rendering nodes and dependent scripts.
<script>
must be placed before </body>
. Do not change the order arbitrarily to prevent loading errors. The search result list template is parsed on the browser side and basically reused ./templates/includes/post-list.ejs, but the summary content <%- post.abstract %>
is modified to <%- post.searchedPreview %>
, using Preview of search results containing keywords.
pagination
field. < div id =" gridea-search-result " data-update =" <%= site.utils.now %> " >
< div class =" searching " >搜索中...... </ div >
< div class =" no-result " style =" display:none " >未搜索到相关文章</ div >
</ div >
< style >
.searched-keyword {
/* <span> 标签支持的所有 CSS 属性 */
}
</ style >
Topics using gridea-search
Official directory structure and page variable description
Third-party libraries:
Front-end fuzzy search - Fuse.js: https://github.com/krisk/fuse
Template parsing - EJS: https://github.com/mde/ejs
Open source license: MIT
Related articles: