Skip to content

Commit 34fb6c2

Browse files
feat(plugin-docsearch): add injectStyles option (close #948) (#1208)
Co-authored-by: meteorlxy <[email protected]>
1 parent 941b2fe commit 34fb6c2

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

docs/reference/plugin/docsearch.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ export default {
316316
- Also see:
317317
- [Guide > I18n](../../guide/i18n.md)
318318

319+
### injectStyles
320+
321+
- Type: `boolean`
322+
323+
- Default: `true`
324+
325+
- Details:
326+
327+
Whether to inject the default styles of DocSearch or not.
328+
329+
If you think the default styles of DocSearch is not compatible with your site, you can try to override the default styles, or set this option to `false` to totally exclude the default styles.
330+
331+
When this option is disabled, you need to import your own styles for DocSearch. Also notice that all styles customization in [Styles](#styles) section would be unavailable.
332+
319333
## Styles
320334

321335
You can customize styles via CSS variables that provided by [@docsearch/css](https://docsearch.algolia.com/docs/styling):

docs/zh/reference/plugin/docsearch.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ export default {
315315
- 参考:
316316
- [指南 > 多语言支持](../../guide/i18n.md)
317317

318+
### injectStyles
319+
320+
- 类型: `boolean`
321+
322+
- 默认值: `true`
323+
324+
- 详情:
325+
326+
是否注入 DocSearch 的默认样式。
327+
328+
如果你认为 DocSearch 的默认样式和你的站点不兼容,你可以尝试覆盖默认样式,或者将该选项设置为 `false` 来完全移除默认样式。
329+
330+
当该选项被禁用时,你需要为 DocSearch 引入你自己的样式。同时要注意,你也无法再使用 [样式](#样式) 章节中提到的样式自定义能力。
331+
318332
## 样式
319333

320334
你可以通过 [@docsearch/css](https://docsearch.algolia.com/docs/styling) 提供的 CSS 变量来自定义样式:

ecosystem/plugin-docsearch/src/client/components/Docsearch.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import type { PropType } from 'vue'
66
import type { DocsearchOptions } from '../../shared/index.js'
77
import { useDocsearchShim } from '../composables/index.js'
88

9-
import '@docsearch/css'
10-
import '../styles/docsearch.css'
9+
declare const __DOCSEARCH_INJECT_STYLES__: boolean
10+
11+
if (__DOCSEARCH_INJECT_STYLES__) {
12+
import('@docsearch/css')
13+
import('../styles/docsearch.css')
14+
}
1115

1216
export const Docsearch = defineComponent({
1317
name: 'Docsearch',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module '@docsearch/css' {
2+
export {}
3+
}
4+
5+
declare module '*.css' {
6+
export {}
7+
}

ecosystem/plugin-docsearch/src/node/docsearchPlugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ import type { DocsearchOptions } from '../shared/index.js'
44

55
const __dirname = getDirname(import.meta.url)
66

7-
export type DocsearchPluginOptions = DocsearchOptions
7+
export interface DocsearchPluginOptions extends DocsearchOptions {
8+
injectStyles?: boolean
9+
}
810

9-
export const docsearchPlugin = (options: DocsearchPluginOptions): Plugin => ({
11+
export const docsearchPlugin = ({
12+
injectStyles = true,
13+
...options
14+
}: DocsearchPluginOptions): Plugin => ({
1015
name: '@vuepress/plugin-docsearch',
1116

1217
clientConfigFile: path.resolve(__dirname, '../client/config.js'),
1318

1419
define: {
1520
__DOCSEARCH_OPTIONS__: options,
21+
__DOCSEARCH_INJECT_STYLES__: injectStyles,
1622
},
1723
})

0 commit comments

Comments
 (0)