此页内容

内容搜索

pengzhanbo

219字小于1分钟

2024-03-06

本地搜索

概述

为站点添加本地搜索。

关联插件: @vuepress-plume/plugin-search

该插件使用 minisearch 进行内容搜索。

默认配置:

import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'

export default defineUserConfig({
  theme: plumeTheme({
    plugins: {
      search: {
        // more options
      }
    }
  })
})

配置

interface SearchOptions {
  /**
   * 本地搜索 国际化
   */
  locales?: {
    [locale: string]: SearchBoxLocale
  }

  /**
   * 文章是否可被搜索,默认为 `() => true`
   */
  isSearchable?: (page: Page) => boolean
}

interface SearchBoxLocale {
  placeholder: string
  buttonText: string
  resetButtonTitle: string
  backButtonTitle: string
  noResultsText: string
  footer: {
    selectText: string
    selectKeyAriaLabel: string
    navigateText: string
    navigateUpKeyAriaLabel: string
    navigateDownKeyAriaLabel: string
    closeText: string
    closeKeyAriaLabel: string
  }
}

Algolia DocSearch

概述

使用 Algolia DocSearch 提供支持的网站内容搜索插件

关联插件:@vuepress/plugin-docsearch

查看 Algolia DocSearch 参考 获取更多信息。

启用

import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'

export default defineUserConfig({
  theme: plumeTheme({
    plugins: {
      docsearch: {
        appId: 'YOUR_APP_ID',
        apiKey: 'YOUR_API_KEY',
        indexName: 'YOUR_INDEX_NAME',
        // more options
      }
    }
  })
})