wzpan / hexo-generator-search

A plugin to generate search data for Hexo.
MIT License
461 stars 83 forks source link

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

Closed boqiang-li closed 6 years ago

boqiang-li commented 6 years ago

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

版本信息:

wzpan commented 6 years ago

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

boqiang-li commented 6 years ago

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

wzpan commented 6 years ago

试试

npm install --save hexo-generator-search@2.2.5 
boqiang-li commented 6 years ago

$ 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"})

boqiang-li commented 6 years ago

补充: $ 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 6 years ago

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

boqiang-li commented 6 years ago

$ 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 6 years ago

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

boqiang-li commented 6 years ago

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

wzpan commented 6 years ago

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

wzpan commented 6 years ago

image

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

boqiang-li commented 6 years ago

您好,我的操作如下: 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

还是无效.....

boqiang-li commented 6 years ago

tim 20180406192421

wzpan commented 6 years ago

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

boqiang-li commented 6 years ago

您好: 已发布。


search //posts/b4f0dba7/ 测试搜索测试搜索测试搜索测试搜索测试搜索

]]>
快排为什么那么快 //posts/ae807e52/
wzpan commented 6 years ago

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

boqiang-li commented 6 years ago

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

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

wzpan commented 6 years ago

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

boqiang-li commented 6 years ago

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

wzpan commented 6 years ago

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

boqiang-li commented 6 years ago

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

wzpan commented 6 years ago

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

boqiang-li commented 6 years ago

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

boqiang-li commented 6 years ago

感谢作者的耐心支持!

xjt927 commented 6 years ago

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

xjt927 commented 6 years ago

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

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

morethink commented 5 years ago

感谢作者的耐心支持!

allinu commented 1 year ago

@all 其实不必修改源码 直接把 permalink 开头的 / 去掉,就行了,这其实是个逻辑问题