dillonzq / LoveIt

❤️A clean, elegant but advanced blog theme for Hugo 一个简洁、优雅且高效的 Hugo 主题
https://hugoloveit.com
MIT License
3.37k stars 1.07k forks source link

Algolia搜索结果的URL出现问题 #421

Open hoasxyz opened 4 years ago

hoasxyz commented 4 years ago

Describe the bug 描述你遇到的错误

假设网站域名为love.it,文章的 slug 和标题均为hello。 那么在网站主页搜索栏中搜索到文章 hello 并点击搜索栏中的该文章后,网站会跳转至love.it/posts/hello。 而如果在 hello 文章页面中搜索文章 hello 并点击搜索栏中的该文章后,网站会跳转至love.it/posts/hello/posts/hello

Expected behavior 期待的行为

不管在该网站的哪个页面,搜素后跳转的都是love.it/hello

Build Environment 构建环境

ZhaoUncle commented 4 years ago

你可以尝试开启这个配置试试: absoluteURL = true

hoasxyz commented 4 years ago

@ZhaoUncle 谢谢,这个配置取消了相对路径,但是 slug 还包括/posts/,请问如何解决呢?

ZhaoUncle commented 4 years ago

你更新了 aloglia 的 json 没有,记住是更新,不是重新添加。

hoasxyz commented 4 years ago

@ZhaoUncle 我是使用hugo-algolia -s在 push 每篇文章之前更新的,应该没问题吧?

ZhaoUncle commented 4 years ago

你应该去 https://www.algolia.com/users/sign_in 检查核对下

hoasxyz commented 4 years ago

@ZhaoUncle 谢谢提醒!那应该就是这个问题了吧:

在 algolia 中 Indices 里,每篇文章的uriobjectID都是posts/xxx,虽然不知道网站中索引的是哪个,但是应该就是二者其一了,容我琢磨琢磨怎么改。

hoasxyz commented 4 years ago

@ZhaoUncle 应该在

[Permalinks]
  # posts = ":year/:month/:filename"
  posts = "/posts/:filename"

中更改每个文章的相对路径,而当我把相对路径改好并设置好absoluteURL = true之后不论是本地预览还是 push 上去搜索结果都是相对路径!有点无语了……

贴个网址:https://hoas.top/

ZhaoUncle commented 4 years ago

这是我默认的配置,没有更改,另外,我建议你先用lunr 本地检查一下是否有问题,如果没问题,那就是 algolia 那里没更新成功。如果有问题,那我建议你把配置还原回 LoveIt 的 example 例子的 config.toml 再进行调整。

[Permalinks]
  # posts = ":year/:month/:filename"
  posts = ":filename
hoasxyz commented 4 years ago

@ZhaoUncle 谢谢!lunr 的本地检查无误!但是 algolia 的更新网上清一色的都是hugo-algolia -s,我这里也是:

$ hugo-algolia -s
JSON index file was created in public/algolia.json
{ updatedAt: '2020-06-24T05:19:32.211Z', taskID: 566594950000 }

这个应该算是成功了吧?不知道哪个环节出了错……

ZhaoUncle commented 4 years ago

你可以试着把 algolia 线上和本地的 index.json 索引记录清空再上传,请自行尝试,因为 lunr 没有问题,所以剩下的自行参考 example。

hoasxyz commented 4 years ago

好的,谢谢你!

ZhaoqiangCn commented 4 years ago

楼主问题解决了吗? 我跟你一样 love.it/posts/hello/posts/hello。

hoasxyz commented 4 years ago

@ZhaoqiangCn 最近我这边 netlify 打不开,再加上有点忙都还没开始尝试,不过根据你的情况反馈以及我早些使用 algolia 的经验来说,这可能是一个 bug。

likakuli commented 3 years ago

我也遇到了同样的问题

Yumian-Cui commented 2 years ago

请问楼主目前解决了吗 我也是一样的问题

lxw15337674 commented 2 years ago

我研究了下,是hugo-algolia生成的路径是相对路径导致的,我改了下源码,新搞了一个包可以解决这个问题。https://github.com/lxw15337674/hugo-lovelt-algolia