Code Monkey home page Code Monkey logo

hexo-generator-search's Introduction

hexo-generator-search

npm npm

Generate search data for Hexo 3.x and 4.x. This plugin is used for generating a search index file, which contains all the neccessary data of your articles that you can use to write a local search engine for your blog. Supports both XML and JSON format output.

Install

$ npm install hexo-generator-search --save

Options

You can configure this plugin in your root _config.yml.

search:
  path: search.xml
  field: post
  content: true
  template: ./search.xml
  • 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 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.
  • 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.
  • template (Optional) - path to a custom XML template

Exclude indexing

To exclude a certain post or page from being indexed, you can simply insert indexing: false setting at the top of its front-matter, e.g.:

title: "Code Highlight"
date: "2014-03-15 20:17:16"
tags: highlight
categories: Demo
description: "A collection of Hello World applications from helloworld.org."
toc: true
indexing: false
---

Then the generated result will not contain this post or page.

FAQ

What's this plugin supposed to do?

This plugin is used for generating a xml / json file from your Hexo blog that provides data for searching.

Where's this file saved to?

After executing hexo g you will get the generated result at your public folder.

How to use this plugin in my Hexo blog?

You have two choices:

  • you don't want to write search engine by yourself. There are many themes that take use this plugin for local searching that works out of box.
  • you are familiar with Ajax and jQuery and would like to write your own search engine. You can implement one by yourself according to the example theme I give. Read the source code of this theme. Generally there are 3 steps:
    1. write a search view. This is the place for displaying a search form and search results ;
    2. write a search script. This script tells the browser how to grab search data and filter out contents what we're searching;
    3. tell hexo to connect the above two part.

hexo-generator-search's People

Contributors

cxgreat2014 avatar forever201406 avatar geekaholiclin avatar kristofzerbe avatar lete114 avatar lorezyra avatar noraj avatar nsa avatar tcrowe avatar wzpan avatar yoshinorin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hexo-generator-search's Issues

How to use this plugin?

What's this plugin supposed to do? Generate a search.xml file, right? Where's this file saved? How do I generate this file?

报错 Unexpected token

hexo next主题
安装好本地搜索后一直报错,删除后重新装也不行,是什么情况,谢谢。

$ npm install hexo-generator-searchdb --save

> [email protected] postinstall E:\Hexo\node_modules\hexo-generator-searchdb\node_modules\hexo-util
> npm run build:highlight


> [email protected] build:highlight E:\Hexo\node_modules\hexo-generator-searchdb\node_modules\hexo-util
> node scripts/build_highlight_alias.js > highlight_alias.json

[email protected] node_modules\hexo-generator-searchdb
├── [email protected]
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

Skye@Skye-pc MINGW64 /e/Hexo (master)
$ hexo s
ERROR Plugin load failed: hexo-generator-searchdb
SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (E:\Hexo\node_modules\hexo-generator-searchdb\node_modules\hexo-util\lib\strip_html.js:3:18)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (E:\Hexo\node_modules\hexo-generator-searchdb\node_modules\hexo-util\lib\index.js:14:21)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (E:\Hexo\node_modules\hexo-generator-searchdb\lib\generator.js:4:12)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (E:\Hexo\node_modules\hexo\lib\hexo\index.js:213:21)
    at E:\Hexo\node_modules\hexo-generator-searchdb\index.js:21:42
    at E:\Hexo\node_modules\hexo\lib\hexo\index.js:229:12
    at tryCatcher (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:502:31)
    at Promise._settlePromise (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:559:18)
    at Promise._settlePromise0 (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:604:10)
    at Promise._settlePromises (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:683:18)
    at Promise._fulfill (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:628:18)
    at Promise._resolveCallback (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:423:57)
    at Promise._settlePromiseFromHandler (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:514:17)
    at Promise._settlePromise (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:559:18)
    at Promise._settlePromise0 (E:\Hexo\node_modules\hexo\node_modules\bluebird\js\release\promise.js:604:10)

关于文章里有非 utf-8 格式的字符时,搜索会卡住

This page contains the following errors:
error on line 53 at column 333: Input is not proper UTF-8, indicate encoding !
Bytes: 0x08 0x50 0x79 0x74
Below is a rendering of the page up to the first error.

用的是 hexo-next-theme 的主题,点击搜索时,一直在加载动画,bug 重现,以及 xml 文件,但是尽管它抛出了具体的行列,目前我锁定不了到底是哪里的字符是非 utf-8 格式,
image

ps: 是不是需要在哪里设置解析的格式为 utf-8 呢?求助

中文转码问题

为什么我的search.xml中文会被html转码?像“**”是"& # x 4 E 2 D ; & # x 5 6 F D ;"

Doesn't link to correct urls

I am in the process of setting up a hexo blog on my github pages.

This search plugin looks pretty impressive, but for some reason results redirect to blog/blog instead of just /blog.

Mind having a look into this?

Problem with hexo-include-markdown

I'm using hexo-include-markdown along with this project.
The content of the generated search.json has something like:

<h2 id="-">Methods</h2>
<!-- md net/_websocketContext/connectSocket.md -->
<!-- md net/_websocketContext/closeSocket.md -->
<!-- md net/_websocketContext/onSocketClose.md -->
...

Is there any thing I can do about it?

Wrong blog post url in search.xml

The issue

When I deploy my hexo website, the search.xml file contains wrong post urls. See below screenshot.

image

This issue causes browser to follow invalid urls such as this http://blog/hackzeugma-ctf-semi-finals-potter-signal-writeup--2020-08-20.html when clicking to the search result.

Could be related to #15. I noticed the issue recently and I cannot be sure if it existed before.

Debug info

In my _config.yml file no option is set related to hexo-generator-search package. I use it with default config. My workaround for this issue is that I changed my custom deploy script to fix these wrong urls with sed command before actually deploying it.

The following is my package.json file for package versions. I may provide more debug info if necessary.

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "4.2.1"
  },
  "dependencies": {
    "hexo": "^4.2.1",
    "hexo-all-minifier": "^0.5.3",
    "hexo-cli": "^4.2.0",
    "hexo-generator-archive": "^0.1.5",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.1",
    "hexo-generator-search": "^2.4.0",
    "hexo-generator-sitemap": "^1.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-nofollow": "^1.0.5",
    "hexo-reference": "^1.0.4",
    "hexo-renderer-ejs": "^0.3.1",
    "hexo-renderer-marked": "^0.3.2",
    "hexo-renderer-stylus": "^0.3.3",
    "hexo-server": "^0.3.3"
  }
}

Thank you for creating hexo-generator-search.

提示有编码错误

This page contains the following errors:

error on line 43 at column 37: Input is not proper UTF-8, indicate encoding !
Bytes: 0xE5 0x8F 0x88 0xE5
Below is a rendering of the page up to the first error.

请问是我的博客编码不对吗?

如何使用search.json?

修改了hexo-generator-search/index.js文件,如下

输出的public/search.json文件是空白的。

搜索结果不能正确跳转


如图,搜索结果的标题 hello world 的 href 链接直接指向博客首页,而不是具体的文章链接。
所有的搜索结果标题链接都指向的是博客首页


感觉好像是 HTML 或者 CSS 上写法的问题?
希望大佬能不吝赐教,指点一二,感谢!

Page does not support tags and categories

if (page.tags && page.tags.length > 0) {
var tags = new Array()
var tag_index = 0
page.tags.each(function (tag) {
tags[tag_index] = tag.name;
});
temp_page.tags = tags
}
if (page.categories && page.categories.length > 0) {
temp_page.categories = []
(page.categories.each || page.categories.forEach)(function (item) {
temp_page.categories.push(item);
});
}

Page does not support tags and categories, need to delete them.

Search with special characters

I got an issue with this plugin. When II got an issue with this plugin. When I search with special characters like c++, the result is empty. While it's ok for just c+, which confuses me a lot.
img
img2
Thanks!

Question about Search field

Hi,
I want to implement your search plugin in my site. I understand that I can generate the search data file, but do you have any tips for how to implement a search field in my page ? I would use something which is already build and not try to write new code. Can you please help ?

Specify a tag or skip some articles when indexing

Firstly, thanks for providing json format instead of xml, which reduces the 3MB search file to 1MB+.

But every time the browser loads an MB file, it will deeply affect the loading speed of the search bar.After I checked search.json file ,I found it seems to read the encrypted article that the search.xml will not read before. and that makes it load a lot of very long code snippets or articles, as well as private articles.

So can I write a simple logical judgment, like if there is an encrypt in the meta, and then skip the content entry of this part of the article?

THX~

Generate JSON response instead

I'm not sure if this feature is already implemented or not, but I would find very useful to retrieve search data as a JSON object instead of XML: it would simplify drastically the parsing process.

Maybe adding a flag to choose response type could be the way to go...

Example of possible JSON search response:

[{
  "title": "Hello World!",
  "url": "/hello-world",
  "type": "html",
  "content": "<p>Hello World!</p>"
}. {
  ...
}, {
  ...
}]

Throw an error

ERROR Plugin load failed: hexo-generator-search
TypeError: Cannot set property 'cdata' of undefined
at Object. (O:_apps\node\work\blog\node_modules\hexo-generator-search\lib\xml_generator.js:5:19)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (O:_apps\node\work\blog\node_modules\hexo\lib\hexo\index.js:216:21)
at O:_apps\node\work\blog\node_modules\hexo-generator-search\index.js:20:40
at O:_apps\node\work\blog\node_modules\hexo\lib\hexo\index.js:232:12
at tryCatcher (O:_apps\node\work\blog\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:693:18)
at Promise._fulfill (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:638:18)
at Promise._resolveCallback (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:432:57)
at Promise._settlePromiseFromHandler (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:524:17)
at Promise._settlePromise (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:693:18)
at Promise._fulfill (O:_apps\node\work\blog\node_modules\bluebird\js\release\promise.js:638:18)

连接出错

网址
在search中点击文章跳转至奇怪网页
http://144.dragonparking.com/?site=yoursite.com&t=1487766968&s=642fabc0f2f80317758b1f21af25e119

生成的 search.xml 中文章的 url,有时候就是附带乱码的,有时候是正常的文章链接

生成的 search.xml 中文章的 url,有时候就是附带乱码的,有时候是正常的文章链接...
概率是:正常1次,乱码2次,如此循环。
但是带乱码的文章 url 有时候能打开链接过去,这时候就形成了一个新的链接地址,如果使用 gitalk 的话,就回生产一个新的 issus ,当然更多时候是出现 404 。

请问下大神这是如何导致的?

No title

Hey,

I use your generator with search.js from the Demo page. I found the glitch if the page doesn't have title:

search.js will show empty <li> for all the pages without title when you search for something, even if there is no any match. I resolved it by setting title for pages which were missing it, but wanted just to inform about the problem.

I am not sure where is the problem — in generator or in search.js. Generated search.xml looks fine...

View all search results

Hi,

Love your work! I am trying to implement search using your search.js file and I have an addition to make. I want to show a button called "View all search results" and show the search results on a new page which is a markdown file.

I could think of two things:

  • Store the search results in an array and store them in sessionStorage.
  • Create a new .json file with the search results in the source/_data/ folder and iterate that in the ejs file.

However, both of these methods seem to fail. Could you please suggest a way to implement this functionality?

Thanks in advance!

Option to include excerpt

I have a site that doesn't want to include all article contents in search.json. We want to keep the size of the json down, and we don't want to make it easier for scrapers to duplicate the content. However, also want better search results that we would get from only using the titles.

We accomplish this by including the excerpts. https://hexo.io/docs/variables#Page-Variables

A new config option should suffice: search.excerpts

It can default to false. Setting it to true would include excerpts where available.

Does anyone have an opinion on how to handle posts that don't have excerpts? It would be easier to implement local searching if the field was included as an empty string, but it would save file size and download time if the field was excluded.

I might go ahead and submit a PR next weekend, so I would love some feedback before then.

关于压缩search.xml文件减小网络下载时间

博客100篇文章左右,search.xml文件有1143KB,试着压缩成zip格式,减少到了399KB。请问作者,可否提供一个压缩选项,减小下载的文件体积,下载到本地后js再解压使用?

search by author?

Hi!

Is it possibile to add the support for searching a post by author?

Jump UL error

Generated search.xml inside 【 %2Fpost%2F4e45b4e3.html 】, When jumping, it will bring http:www.xxx.com/search/%2Fpost%2F4e45b4e3.html. error. How to make ‘/ ’ do‘t transcode to ’%2F’.please.

Process html pages from theme/source

It is a feature request.

I have *.html files in the theme/source, so these files are not getting rendered but just copied to the public directory. I would like this content also to be added to search.xml. Is it possible?

搜索加载失败

image

请问一下,这个错误信息中的位置信息,要怎么定位到具体到文本错误位置:

error on line 38 at column 35: Input is not proper UTF-8, indicate encoding !

image

新年第一个问题...关于搜索结果

我在hexo根目录下将content设置为false以后, 无论搜索什么内容都会出现所有的博客,找了挺久但是没找到解决办法,麻烦您在有时间的时候能予以解惑,非常感谢~祝您新年快乐

issue
content

搜索结果链接没有网站url问题

Expected behavior

在搜索的结果中,文章链接到正确的地址。

Actual behavior

超链接是以post开头的一个相对路径

Steps to reproduce the behavior

  1. 安装 npm install --save hexo-generator-search
  2. 安装 npm install --save hexo-generator-searchdb
  3. 站点配置文件中添加:
    search:
    path: search.xml
    field: post
    format: html
    limit: 10000

主题配置文件中添加了我的url:
url: http://littlesevenmo.github.io

开启了 local search: true

版本信息:

搜索结果url问题

作者好,感谢你提供的插件,让我受益。

反馈个小问题,也可能是我自己的原因,麻烦帮我看一下。
我的博客文章,搜索后,从搜索结果跳转到文章的url和我在主页点的不一样,这个看起来不咋影响。
image

image

如上两幅图所示,其实是同一篇文章,前面是我从首页点的,后面是我自己跳转的,url不一样,导致一个尴尬的问题是,我用的评论gitalk是根据url来的,就导致我一个问题,同一篇文章会初始化2个评论……互相不可见……
image

不知道有没有办法破解?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.