VuepressThemeHope
2023/3/23大约 2 分钟
介绍
本网站使用vuepress-theme-hope搭建。
文档:https://theme-hope.vuejs.press/zh/
仓库:https://github.com/vuepress-theme-hope/vuepress-theme-hope
Algolia 文档搜索配置:https://theme-hope.vuejs.press/zh/guide/feature/search.html
Algolia 配置
爬虫所需配置。
Algolia Crawler
new Crawler({
appId: "你的应用ID",
rateLimit: 8,
startUrls: ["https://zhiyu.wiki/"],
sitemaps: ["https://zhiyu.wiki/sitemap.xml"],
ignoreCanonicalTo: false,
exclusionPatterns: [],
discoveryPatterns: ["https://zhiyu.wiki/**"],
schedule: "at 11:00 every 3 day",
actions: [
{
indexName: "你的indexName",
pathsToMatch: ["https://zhiyu.wiki/**"],
recordExtractor: ({ $, helpers }) => {
return helpers.docsearch({
recordProps: {
lvl0: {
selectors: [".vp-sidebar-link.active", "[vp-content] h1"],
defaultValue: "Documentation",
},
lvl1: "[vp-content] h1",
lvl2: "[vp-content] h2",
lvl3: "[vp-content] h3",
lvl4: "[vp-content] h4",
lvl5: "[vp-content] h5",
lvl6: "[vp-content] h6",
content: "[vp-content] p, [vp-content] li",
},
recordVersion: "v3",
});
},
},
],
initialIndexSettings: {
你的indexName: {
attributesForFaceting: ["type", "lang"],
attributesToRetrieve: ["hierarchy", "content", "anchor", "url"],
attributesToHighlight: ["hierarchy", "hierarchy_camel", "content"],
attributesToSnippet: ["content:10"],
camelCaseAttributes: ["hierarchy", "hierarchy_radio", "content"],
searchableAttributes: [
"unordered(hierarchy_radio_camel.lvl0)",
"unordered(hierarchy_radio.lvl0)",
"unordered(hierarchy_radio_camel.lvl1)",
"unordered(hierarchy_radio.lvl1)",
"unordered(hierarchy_radio_camel.lvl2)",
"unordered(hierarchy_radio.lvl2)",
"unordered(hierarchy_radio_camel.lvl3)",
"unordered(hierarchy_radio.lvl3)",
"unordered(hierarchy_radio_camel.lvl4)",
"unordered(hierarchy_radio.lvl4)",
"unordered(hierarchy_radio_camel.lvl5)",
"unordered(hierarchy_radio.lvl5)",
"unordered(hierarchy_radio_camel.lvl6)",
"unordered(hierarchy_radio.lvl6)",
"unordered(hierarchy_camel.lvl0)",
"unordered(hierarchy.lvl0)",
"unordered(hierarchy_camel.lvl1)",
"unordered(hierarchy.lvl1)",
"unordered(hierarchy_camel.lvl2)",
"unordered(hierarchy.lvl2)",
"unordered(hierarchy_camel.lvl3)",
"unordered(hierarchy.lvl3)",
"unordered(hierarchy_camel.lvl4)",
"unordered(hierarchy.lvl4)",
"unordered(hierarchy_camel.lvl5)",
"unordered(hierarchy.lvl5)",
"unordered(hierarchy_camel.lvl6)",
"unordered(hierarchy.lvl6)",
"content",
],
},
},
apiKey: "key",
});注意,对应的 Indices index 需要修改配置(模版创建时的默认配置),否则部分索引搜索后不显示:
Configuration → Filtering and faceting → Facets → Attributes for faceting
加入lang、typeConfiguration → Relevance Optimizations → Language → Index Languages
改为 Chinese
最后重新运行爬虫。
theme-hope config
docsearch: {
appId: '你的应用ID',
apiKey: '你的 search key',
indices: ['indexName'],
placeholder: '搜索文档',
locales: {
'/': {
placeholder: '搜索文档',
translations: {
button: {
buttonText: '搜索文档',
buttonAriaLabel: '搜索文档',
},
modal: {
searchBox: {
clearButtonTitle: '清除查询条件',
clearButtonAriaLabel: '清除查询条件',
closeButtonText: '取消',
closeButtonAriaLabel: '取消',
},
startScreen: {
recentSearchesTitle: '搜索历史',
noRecentSearchesText: '没有搜索历史',
saveRecentSearchButtonTitle: '保存至搜索历史',
removeRecentSearchButtonTitle: '从搜索历史中移除',
favoriteSearchesTitle: '收藏',
removeFavoriteSearchButtonTitle: '从收藏中移除',
},
errorScreen: {
titleText: '无法获取搜索结果',
helpText: '请检查网络连接。',
},
footer: {
selectText: '选择',
navigateText: '切换',
closeText: '关闭',
},
noResultsScreen: {
noResultsText: '没有找到相关结果',
suggestedQueryText: '你可以尝试搜索',
reportMissingResultsText: '认为应该有结果?',
reportMissingResultsLinkText: '反馈问题',
},
},
},
},
},
}