美兰十三的想疗院


一个不务正业的前端狗,爱纹身、玩乐队、哥金党、专门写Bug~


给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

WX20170515-155458-2x
WX20170515-161908-2x


使用方法(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

建议打赏金额1-10元

支付宝打赏

微信打赏

最近的文章

另一种Ghost站内搜索不需要Lunr 和 jQuery(another way to add Search Fn to Ghost Blog, No need Lunr & jQuery )

语言 / Language * 中文说明 * EN 中文说明 上一篇文章中 我们使用了 GhostHunter 作为ghost博客的站内搜索引擎, 但是GhostHunter 是基…

GHOST, GhostBot 继续阅读
更早的文章

华丽的蜕变,放弃node-forever 改用 pm2

因为我的博客是ghost,基于node的,所以关闭shell的之后需要有额外工具来帮住守护住 ghost的 进程,不然一旦shell关闭 博客也就无法访问了。 之前我一直使用的forever来守护g…

pm2, forever 继续阅读
comments powered by Disqus
沪ICP备15043964号-3