给Ghost加入站内搜索(Add Search Fn to Ghost Blog)

项目地址:
Project Addr:

此项目Fork 自ghostHunter, 一个基于Lunr的Ghost 站内搜索引擎。。。
Forked From ghostHunter,A Ghost blog search engine based on Lunr.js

原版GhostHunter缺陷:
The Original GhostHunter Defects:

  1. 不支持中文搜索
    Not Support Chinese pinyin
  2. 搜索源来自Ghost的Rss
    search from RSS

此版本针对以上2点做了更新;
This Version update this 2 points;

不支持中文搜索(Not Support Chinese pinyin)

原版GhostHunter 是根据文章的 slug/url进行搜索的,对英文无关紧要,但是遇到含有拼音的中文等就尴尬了。。。任何拼音语言 去搜索 结果都是“0”,因为slug里只会有字母+数字+横杠
The Original GhostHunter runs search by querying the slug/url. So if we use Chinese pinyin, the results are always 0, because the Slug only include "letter、 Number、-", so we do some update to make GhostHunter support Chinese pinyin(we changed some lunr source code)

RSS为搜索源(search from RSS)

ghost的rss只会显示最新的15条博文,于是乎 对于超过15条博文的博主来说,搜索就很尴尬了。。。无法搜索到 最近15条以前的博文。。。
the Rss in Ghost only show the latest 15 posts. So if your posts are more then 15, we can not get the results out of the latest 15 posts.

于是乎此版本 就改为使用 Ghost 实验功能的开放API,原本的 LoadRSS更改为LoadAPI,在初次的时候 先使用ghost的api获取文章列表,然后在获取到的所有文章列表里进行 搜索,这样就能进行全站搜索了。。。
So, we change RSS to API. We change 'LoadRss' to 'LoadAPI'. When init your blog, we get all posts through the API, and then we make all posts to be a list, and we search posts in this list. So we can search all of the posts

所以,请在Ghost后台 的实验功能里选中开放API
So, Please make the Public API checked



使用方法(Usage)

如同原版 GhostHunter一样
like original GhostHunter

  • </body>jquery文件 后 引入 js文件
    After including jQuery, include ghostHunter before </body>
<script src="js/jquery.ghostHunter.min.js"></script>
  • 创建搜索框的DOM
    create search DOM
<form>
   <input id="search-field" />
   <input type="submit" value="search">
</form>
  • 创建搜索结果的DOM
    create result DOM
<section id="results"></section>
  • 使用ghostHunter
    Now we can turn on the plugin, and that’s all there is to it
$("#search-field").ghostHunter({
    results   : "#results"
});

详细用法 请移步 coding 或 github
Please turn to Coding or Github to See More Detail