wzpan/hexo-generator-search

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

boqiang-li opened this issue · 28 comments

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

版本信息:

  • hexo-generator-search@2.2.5
wzpan commented

你这个 search.xml 不是最新的版本生成的。你可以和 demo_output.xml 比对,新的版本生成的 xml 会有 link 和 url 两种标签对。

请问该如何解决,我重新安装,clean generate之后,还是无效

wzpan commented

试试

npm install --save hexo-generator-search@2.2.5 

$ npm install --save hexo-generator-search@2.2.5
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

  • hexo-generator-search@2.2.5
    updated 1 package in 8.342s

$ hexo clean
INFO Deleted database.
INFO Deleted public folder.

$ hexo generate
INFO Start processing
INFO Files loaded in 918 ms
INFO Generated: search.xml
INFO Generated: atom.xml
INFO Generated: index.html
INFO Generated: about/index.html
INFO Generated: categories/index.html
INFO Generated: archives/index.html
INFO Generated: tags/password/index.html
INFO Generated: posts/ae807e52/index.html
INFO Generated: uploads/logo.jpg
INFO Generated: posts/4d6b513d/1.jpg
INFO Generated: archives/2018/03/index.html
INFO Generated: posts/35c246d5/index.html
INFO Generated: images/avatar.gif
INFO Generated: categories/algorithm/index.html
INFO Generated: tags/算法/index.html
INFO Generated: posts/c53d045f/1.jpg
INFO Generated: images/algolia_logo.svg
INFO Generated: images/cc-by-nc-nd.svg
INFO Generated: images/cc-by-nc-sa.svg
INFO Generated: images/cc-by-nc.svg
INFO Generated: images/cc-by-nd.svg
INFO Generated: posts/7a6a6b5a/index.html
INFO Generated: images/cc-by-sa.svg
INFO Generated: images/cc-by.svg
INFO Generated: images/loading.gif
INFO Generated: images/cc-zero.svg
INFO Generated: images/placeholder.gif
INFO Generated: images/favicon.ico
INFO Generated: images/quote-l.svg
INFO Generated: images/logo.jpg
INFO Generated: images/searchicon.png
INFO Generated: images/quote-r.svg
INFO Generated: archives/2018/index.html
INFO Generated: posts/c53d045f/index.html
INFO Generated: posts/4d6b513d/index.html
INFO Generated: tags/测试/index.html
INFO Generated: lib/fastclick/LICENSE
INFO Generated: lib/font-awesome/HELP-US-OUT.txt
INFO Generated: lib/algolia-instant-search/instantsearch.min.css
INFO Generated: lib/canvas-nest/canvas-nest.min.js
INFO Generated: lib/fastclick/README.html
INFO Generated: lib/canvas-ribbon/canvas-ribbon.js
INFO Generated: lib/font-awesome/bower.json
INFO Generated: lib/fastclick/bower.json
INFO Generated: lib/jquery_lazyload/CONTRIBUTING.html
INFO Generated: lib/jquery_lazyload/README.html
INFO Generated: lib/jquery_lazyload/bower.json
INFO Generated: lib/pace/pace-theme-barber-shop.min.css
INFO Generated: lib/pace/pace-theme-center-atom.min.css
INFO Generated: lib/jquery_lazyload/jquery.scrollstop.js
INFO Generated: lib/jquery_lazyload/jquery.lazyload.js
INFO Generated: lib/pace/pace-theme-bounce.min.css
INFO Generated: lib/pace/pace-theme-center-radar.min.css
INFO Generated: lib/pace/pace-theme-center-simple.min.css
INFO Generated: lib/pace/pace-theme-fill-left.min.css
INFO Generated: lib/pace/pace-theme-center-circle.min.css
INFO Generated: lib/pace/pace-theme-corner-indicator.min.css
INFO Generated: lib/pace/pace-theme-flash.min.css
INFO Generated: lib/pace/pace-theme-loading-bar.min.css
INFO Generated: lib/pace/pace-theme-big-counter.min.css
INFO Generated: lib/pace/pace-theme-minimal.min.css
INFO Generated: lib/pace/pace-theme-mac-osx.min.css
INFO Generated: lib/pace/pace.min.js
INFO Generated: lib/velocity/bower.json
INFO Generated: css/main.css
INFO Generated: lib/three/canvas_sphere.min.js
INFO Generated: lib/velocity/velocity.min.js
INFO Generated: lib/velocity/velocity.ui.min.js
INFO Generated: lib/three/three-waves.min.js
INFO Generated: lib/jquery/index.js
INFO Generated: lib/three/canvas_lines.min.js
INFO Generated: lib/velocity/velocity.ui.js
INFO Generated: lib/font-awesome/fonts/fontawesome-webfont.woff
INFO Generated: lib/velocity/velocity.js
INFO Generated: lib/algolia-instant-search/instantsearch.min.js
INFO Generated: lib/three/three.min.js
INFO Generated: lib/font-awesome/fonts/fontawesome-webfont.woff2
INFO Generated: lib/font-awesome/fonts/fontawesome-webfont.svg
INFO Generated: lib/Han/dist/font/han-space.otf
INFO Generated: lib/fancybox/source/helpers/fancybox_buttons.png
INFO Generated: lib/fancybox/source/fancybox_loading.gif
INFO Generated: lib/fancybox/source/fancybox_loading@2x.gif
INFO Generated: lib/fancybox/source/blank.gif
INFO Generated: lib/fancybox/source/fancybox_overlay.png
INFO Generated: lib/Han/dist/font/han.woff
INFO Generated: lib/Han/dist/font/han-space.woff
INFO Generated: lib/fancybox/source/fancybox_sprite@2x.png
INFO Generated: lib/font-awesome/css/font-awesome.css.map
INFO Generated: lib/fancybox/source/fancybox_sprite.png
INFO Generated: js/src/affix.js
INFO Generated: lib/ua-parser-js/dist/ua-parser.min.js
INFO Generated: lib/fastclick/lib/fastclick.min.js
INFO Generated: js/src/exturl.js
INFO Generated: lib/Han/dist/font/han.otf
INFO Generated: js/src/algolia-search.js
INFO Generated: js/src/bootstrap.js
INFO Generated: js/src/js.cookie.js
INFO Generated: js/src/hook-duoshuo.js
INFO Generated: js/src/scroll-cookie.js
INFO Generated: js/src/scrollspy.js
INFO Generated: js/src/motion.js
INFO Generated: js/src/post-details.js
INFO Generated: lib/fancybox/source/helpers/jquery.fancybox-buttons.css
INFO Generated: lib/ua-parser-js/dist/ua-parser.pack.js
INFO Generated: js/src/utils.js
INFO Generated: lib/fancybox/source/jquery.fancybox.css
INFO Generated: lib/fancybox/source/helpers/jquery.fancybox-buttons.js
INFO Generated: lib/fancybox/source/helpers/jquery.fancybox-media.js
INFO Generated: lib/Han/dist/han.css
INFO Generated: lib/fancybox/source/helpers/jquery.fancybox-thumbs.js
INFO Generated: lib/fancybox/source/helpers/jquery.fancybox-thumbs.css
INFO Generated: lib/font-awesome/css/font-awesome.min.css
INFO Generated: lib/Han/dist/han.min.css
INFO Generated: lib/fancybox/source/jquery.fancybox.js
INFO Generated: lib/Han/dist/han.min.js
INFO Generated: lib/fastclick/lib/fastclick.js
INFO Generated: lib/fancybox/source/jquery.fancybox.pack.js
INFO Generated: lib/font-awesome/css/font-awesome.css
INFO Generated: lib/font-awesome/fonts/fontawesome-webfont.ttf
INFO Generated: lib/font-awesome/fonts/FontAwesome.otf
INFO Generated: lib/font-awesome/fonts/fontawesome-webfont.eot
INFO Generated: lib/Han/dist/han.js
INFO Generated: js/src/schemes/pisces.js
INFO 123 files generated in 1.74 s

依然无效

补充:
$ hexo --version
hexo: 3.7.0
hexo-cli: 1.1.0
os: Windows_NT 10.0.16299 win32 x64
http_parser: 2.8.0
node: 8.11.1
v8: 6.2.414.50
uv: 1.19.1
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 57
nghttp2: 1.25.0
openssl: 1.0.2o
icu: 60.1
unicode: 10.0
cldr: 32.0
tz: 2017c
感谢老师,不胜感激!

wzpan commented

cat 一下 node_modules/hexo-generator-search/package.json 看一下什么内容。

$ cat node_modules/hexo-generator-search/package.json
{
"_from": "hexo-generator-search@2.2.5",
"_id": "hexo-generator-search@2.2.5",
"_inBundle": false,
"_integrity": "sha512-lt2qEGhNINOcQr2ws7UKXAOALWz8Z0+fuq88mbJgQogpUhXrLLfJiv/padHBatooTFeK7+XBUDDS6mgfKMbrkg==",
"_location": "/hexo-generator-search",
"_nodeVersion": "0.12.4",
"_npmUser": {
"name": "wzpan",
"email": "m@hahack.com"
},
"_npmVersion": "2.11.0",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "hexo-generator-search@2.2.5",
"name": "hexo-generator-search",
"escapedName": "hexo-generator-search",
"rawSpec": "2.2.5",
"saveSpec": null,
"fetchSpec": "2.2.5"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/hexo-generator-search/-/hexo-generator-search-2.2.5.tgz",
"_shasum": "624b16992a58d9382f51a8b144526cc7a08e1c9b",
"_spec": "hexo-generator-search@2.2.5",
"_where": "F:\Blog\test",
"author": {
"name": "wzpan",
"email": "m@hahack.com",
"url": "https://github.com/Wzpan"
},
"bugs": {
"url": "https://github.com/Wzpan/hexo-generator-search/issues"
},
"bundleDependencies": false,
"dependencies": {
"nunjucks": "^3.0.1",
"utils-merge": "^1.0.0"
},
"deprecated": false,
"description": "Seach generator plugin for Hexo",
"directories": {
"lib": "./lib"
},
"engines": {
"node": ">= 0.10.0"
},
"homepage": "https://github.com/Wzpan/hexo-generator-search#readme",
"keywords": [
"hexo",
"search",
"generator"
],
"license": "MIT",
"main": "index",
"maintainers": [
{
"name": "maoshuhao",
"email": "326810048@qq.com"
},
{
"name": "wzpan",
"email": "m@hahack.com"
}
],
"name": "hexo-generator-search",
"repository": {
"type": "git",
"url": "git+https://github.com/Wzpan/hexo-generator-search.git"
},
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"version": "2.2.5"
}

wzpan commented

手动删掉 db.json 和 public 目录再试呢?这个版本是不会生成像你现在的站点里的 search.xml 的。

手动删除 网站根目录下的db.json 和public目录之后
1)hexo generate 结果仍然是错误的
2)hexo clean hexo generate 也是错误的。

wzpan commented

这个 hexo-generator-searchdb 是做什么用的?删掉它呢?

wzpan commented

image

hexo-generator-searchdb 的描述来看,这个东西只是 hexo-generator-search 的一个 fork,你们不需要装两个。

您好,我的操作如下:
1,$ npm uninstall hexo-generator-searchdb
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 13 packages and removed 3 packages in 19.202s

确保node_modules目录里没有hexo-generator-searchdb
2,手动删除 网站根目录下的 db.json 和 public 目录

3,hexo clean hexo generate

还是无效.....

wzpan commented

你发布一下我看下search.xml的内容

您好:
已发布。


<title>search</title> //posts/b4f0dba7/ 测试搜索测试搜索测试搜索测试搜索测试搜索

]]> <title>快排为什么那么快</title> //posts/ae807e52/
wzpan commented

你的 _config.yml 里的 url 和 root 分别是怎么设置的?

您好:
站点配置文件:
url: https://littlesevenmo.github.io
root: /

主题配置文件:
url: https://littlesevenmo.github.io

wzpan commented

看起来没问题。让我很奇怪的是,你的 url 被 hexo 解析成了 / ,然后和文章的路径加在一起了。

搜索结果解析出来的是 https://posts/7a6a6b5a/ 看样子是直接没有我的url

wzpan commented

有一种可能性是因为你用的是 windows 。另外试试将 hexo 降级至 3.3.7 ,因为我本地用的是 3.3.7 这个版本。

其实我也试过按照官方教程https://theme-next.iissnan.com/third-party-services.html#search-system
重新建了个博客,还是有错误

wzpan commented

我建议你不要使用windows来搭建 hexo 博客

感谢!
最后成功解决了。解决方法在这里

感谢作者的耐心支持!

@littlesevenmo 请问你是怎么解决的,我也遇到这个问题,搜索结果为http://posts/b26bcbc1/
iissnan/hexo-theme-next#1852 这里得解决方案不知道具体怎么操作。
//var articleUrl = decodeURIComponent(data.url);
var articleUrl = decodeURIComponent(data.url).substring(1);//截取第一位/斜杠

解决了,在localsearch.swig文件下修改
hexo\themes\next\layout_third-party\search\localsearch.swig

//var articleUrl = decodeURIComponent(data.url);
var articleUrl = decodeURIComponent(data.url).substring(1);//截取第一位/斜杠

感谢作者的耐心支持!