airene / vitepress-blog-pure

a vitepress theme for blog, demo ↓
https://ti.bi
MIT License
183 stars 26 forks source link

可以加个文章内容搜索功能吗 #15

Closed zkrisj closed 5 months ago

zkrisj commented 1 year ago

因为我的文章比较多,想搜索某个文章的内容很麻烦,或者大佬给个文章搜索的实现方法

airene commented 1 year ago

https://vitepress.dev/reference/default-theme-search 按照这个操作就行了,就是加点配置的事 😊

zkrisj commented 1 year ago

https://vitepress.dev/reference/default-theme-search 按照这个操作就行了,就是加点配置的事 😊

好的,多谢了

zkrisj commented 1 year ago

import { defineConfig } from 'vitepress'

export default defineConfig({ themeConfig: { algolia: { appId: '48REP6ZA9O', apiKey: '3482029dd8400cbaa54eff5893aabb62', indexName: 'dev_zkrisj', } } }) 我这么配置了,怎么搜索都没有结果呢 image

https://vitepress.dev/reference/default-theme-search 按照这个操作就行了,就是加点配置的事 😊

zkrisj commented 1 year ago

ChatGPT给的建议:

  1. 数据是否已经成功导入到Algolia的搜索索引中,可以在Algolia的网站上查看数据是否已经被正确地索引。
  2. 搜索索引的schema是否与你的博客数据格式和字段一致,需要保持一致才能进行搜索。
airene commented 1 year ago

这个是vitepress提供的集成能力,如果刚配置(配置正确)的话,可以等等看安是不是有类似“爬取”或者叫同步的时间

aiktb commented 1 year ago
  1. Algolia

Algolia的配置需要去Algolia官网申请才能使用,在你的网站没有内容之前是不会通过的 想要使用搜索功能我建议使用本地搜索vitepress-plugin-search 过个一年半载,网站丰富了,再去申请Algolia 至于文档中的

search: {
      provider: 'local'
    }

我并没有在vitepress的接口中找到"search“,有理由怀疑是文档错误

airene commented 1 year ago
  1. Algolia

Algolia的配置需要去Algolia官网申请才能使用,在你的网站没有内容之前是不会通过的 想要使用搜索功能我建议使用本地搜索vitepress-plugin-search 过个一年半载,网站丰富了,再去申请Algolia 至于文档中的

search: {
      provider: 'local'
    }

我并没有在vitepress的接口中找到"search“,有理由怀疑是文档错误

最新的版本或者或者说最近的刚加的本地搜索,我还没更新,不知道你看的是什么版本的代码,打算最近几天测试一下本地搜索更新一下。

zkrisj commented 1 year ago

官网的配置有点复杂,到第二步就不知道怎么弄了

www algolia com_apps_48REP6ZA9O_onboarding

zkrisj commented 1 year ago
  1. Algolia

Algolia的配置需要去Algolia官网申请才能使用,在你的网站没有内容之前是不会通过的 想要使用搜索功能我建议使用本地搜索vitepress-plugin-search 过个一年半载,网站丰富了,再去申请Algolia 至于文档中的

search: {
      provider: 'local'
    }

我并没有在vitepress的接口中找到"search“,有理由怀疑是文档错误

aiktb commented 1 year ago
  1. Algolia

Algolia的配置需要去Algolia官网申请才能使用,在你的网站没有内容之前是不会通过的 想要使用搜索功能我建议使用本地搜索vitepress-plugin-search 过个一年半载,网站丰富了,再去申请Algolia 至于文档中的

search: {
      provider: 'local'
    }

我并没有在vitepress的接口中找到"search“,有理由怀疑是文档错误

我已经升级到1.0.0-alpha.74,provider: 'local'已被支持,但不能识别中文。 这个自带的主题比vitepress-plugin-search的好看很多。 因为我没啥这种需求,就这样了,以后搞Algolia吧

airene commented 1 year ago

Algolia 应该不复杂吧,回头我试一下哈

zkrisj commented 1 year ago

Algolia 应该不复杂吧,回头我试一下哈

👌好的

airene commented 1 year ago

看了一下Algolia还是有点复杂,配置到vitepress很简单,麻烦的是总体Algolia是数据要上报到Algolia那才行,上报方式有: 1、主动上报json 2、在构建阶段上报,比如用的是git action的话相对就比较方便 3、用Algolia的爬虫爬(我一直以为这个是自动且免费的,结果这个是一个付费服务

综述:直接用local方式的搜索可能更简单点了, vitepress版本有要求,官方一直在迭代这个功能。 ps: 用local search目前对文章中的 第一行内容(标题) 写成# {{ $frontmatter.title }}这个有缺陷,很容易复现 https://vitepress.dev/reference/default-theme-search#algolia-search

welpher commented 8 months ago

非常感谢,我用了您的样式