[Hexo] Use hexo-generator-searchdb plugin and hexo-theme-next (NexT) theme to enable local search in Hexo
hexo-generator-searchdb
Hexo is a fast, simple & powerful blog framework. It use plugins to provide features powerful APIs for limitless extensibility. Various plugins are available to support most template engines (EJS, Pug, Nunjucks, and many others). Easily integrate with existing NPM packages (Babel, PostCSS, Less/Sass, etc).
hexo-generator-searchdb
is used for generating a search index file, which contains all the necessary data of your articles that you can use to write a local search engine for your blog. Supports both XML and JSON format output.
Installation
Use npm
to install hexo-generator-searchdb
package.
1 | npm install hexo-generator-searchdb |
Configuration
First, configure this plugin in your Hexo root _config.yml
. All the arguments are optional.
1 | # _config.yml |
The follow is the options:
-
path - file path. By default is search.xml. If the file extension is .json, the output format will be JSON. Otherwise XML format file will be exported.
-
field - the search scope you want to search, you can chose:
-
post (Default) - will only cover all the posts of your blog.
-
page - will only cover all the pages of your blog.
-
all - will cover all the posts and pages of your blog.
-
-
content - whether contains the whole content of each article. If false, the generated results only cover title and other meta info without mainbody. By default is true.
-
format - the form of the page contents, options are:
-
html (Default) - original html string being minified.
-
striptags - original html string being minified, and remove all the tags.
-
raw - markdown text of each posts or pages.
-
Then, configure this plugin in your hexo-theme-next
plugin _config_next.yml
.
1 | # _config_next.yml |
Finally, you can visit your site in the browser, and check whether the site works correctly after Hexo restarted or regenerated.
References
[4] next-theme/awesome-next: 😎 Theme NexT, AWESOME NexT! - https://github.com/next-theme/awesome-next