个人博客搭建hexo+github(9):本地搜索

本地搜索,不需要依赖外部的搜索服务,简单易用。

安装hexo-generator-searchdb

npm install hexo-generator-searchdb --save

配置

hexo(~不是主题的~)的 _config.yml 中增加配置

1
2
3
4
5
search:
path: search.xml
field: post
format: raw
limit: 10000
  • path - file path. Default is search.xml .
  • field - the search scope you want to search, you can chose:
    • post (Default) - will only covers all the posts of your blog.
    • page - will only covers all the pages of your blog.
    • all - will covers all the posts and pages of your blog.
  • format - the form of the page contents, options are:
    • html (Default) - original html string being minified.
    • raw - markdown text of each posts or pages.
    • excerpt - only collect excerpt.
    • more - act as you think.
  • limit - define the maximum number of posts being indexed, always prefer the newest.

效果

local_search_example.png

Reference:

  1. hexo-generator-searchdb