From 0294b7a8109794ad1ae45364cab24cdd8391c23d Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Fri, 9 Apr 2021 01:15:37 +0800 Subject: [PATCH] docs(plugin-docsearch): add example crawler config --- docs/reference/plugin/docsearch.md | 37 +++++++++++++++++++++++++++ docs/zh/reference/plugin/docsearch.md | 37 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/docs/reference/plugin/docsearch.md b/docs/reference/plugin/docsearch.md index 9ae1e807e8..9025d29b00 100644 --- a/docs/reference/plugin/docsearch.md +++ b/docs/reference/plugin/docsearch.md @@ -16,6 +16,43 @@ You need to [submit the URL of your site](https://docsearch.algolia.com/apply/) Alternatively, you can [run your own crawler](https://docsearch.algolia.com/docs/run-your-own/) to generate the index, and then use your own [appId](#appId), [apiKey](#apikey) and [indexName](#indexname) to configure this plugin. +::: details Click to show the example crawler config +```json{19-23,25-27} +{ + "index_name": "your_index_name", + "start_urls": [ + "https://your.domain.name/" + ], + "stop_urls": [], + "selectors": { + "lvl0": { + "selector": "p.sidebar-heading.active", + "global": true, + "default_value": "Documentation" + }, + "lvl1": ".theme-default-content h1", + "lvl2": ".theme-default-content h2", + "lvl3": ".theme-default-content h3", + "lvl4": ".theme-default-content h4", + "lvl5": ".theme-default-content h5", + "text": ".theme-default-content p, .theme-default-content li", + "lang": { + "selector": "/html/@lang", + "type": "xpath", + "global": true + } + }, + "custom_settings": { + "attributesForFaceting": ["lang"] + } +} +``` + +The above `selectors` is the configuration used for the default theme. You can modify them according to the theme you are using. + +Notice that the `selectors.lang` and the `custom_settings.attributesForFaceting` fields are **required** to make this plugin work properly. +::: + ## Options ### apiKey diff --git a/docs/zh/reference/plugin/docsearch.md b/docs/zh/reference/plugin/docsearch.md index 7ecb3e0e10..5ce28abe12 100644 --- a/docs/zh/reference/plugin/docsearch.md +++ b/docs/zh/reference/plugin/docsearch.md @@ -16,6 +16,43 @@ 或者,你也可以 [运行你自己的爬虫](https://docsearch.algolia.com/docs/run-your-own/) 来创建索引,然后使用你自己的 [appId](#appId), [apiKey](#apikey) 和 [indexName](#indexname) 来配置该插件。 +::: details 点击查看爬虫配置示例 +```json{19-23,25-27} +{ + "index_name": "your_index_name", + "start_urls": [ + "https://your.domain.name/" + ], + "stop_urls": [], + "selectors": { + "lvl0": { + "selector": "p.sidebar-heading.active", + "global": true, + "default_value": "Documentation" + }, + "lvl1": ".theme-default-content h1", + "lvl2": ".theme-default-content h2", + "lvl3": ".theme-default-content h3", + "lvl4": ".theme-default-content h4", + "lvl5": ".theme-default-content h5", + "text": ".theme-default-content p, .theme-default-content li", + "lang": { + "selector": "/html/@lang", + "type": "xpath", + "global": true + } + }, + "custom_settings": { + "attributesForFaceting": ["lang"] + } +} +``` + +上述 `selectors` 是用于默认主题的配置,你可以根据你使用的主题来修改它们。 + +注意 `selectors.lang` 和 `custom_settings.attributesForFaceting` 字段,它们是**必须**的,否则该插件将无法正常工作。 +::: + ## 配置项 ### apiKey