Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-docsearch): add injectStyles option #1208

Merged
merged 4 commits into from Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/reference/plugin/docsearch.md
Expand Up @@ -316,6 +316,20 @@ export default {
- Also see:
- [Guide > I18n](../../guide/i18n.md)

### injectStyles

- Type: `boolean`

- Default: `true`

- Details:

Whether to inject the default styles of DocSearch or not.

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.

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.

## Styles

You can customize styles via CSS variables that provided by [@docsearch/css](https://docsearch.algolia.com/docs/styling):
Expand Down
14 changes: 14 additions & 0 deletions docs/zh/reference/plugin/docsearch.md
Expand Up @@ -315,6 +315,20 @@ export default {
- 参考:
- [指南 > 多语言支持](../../guide/i18n.md)

### injectStyles

- 类型: `boolean`

- 默认值: `true`

- 详情:

是否注入 DocSearch 的默认样式。

如果你认为 DocSearch 的默认样式和你的站点不兼容,你可以尝试覆盖默认样式,或者将该选项设置为 `false` 来完全移除默认样式。

当该选项被禁用时,你需要为 DocSearch 引入你自己的样式。同时要注意,你也无法再使用 [样式](#样式) 章节中提到的样式自定义能力。

## 样式

你可以通过 [@docsearch/css](https://docsearch.algolia.com/docs/styling) 提供的 CSS 变量来自定义样式:
Expand Down
8 changes: 6 additions & 2 deletions ecosystem/plugin-docsearch/src/client/components/Docsearch.ts
Expand Up @@ -6,8 +6,12 @@ import type { PropType } from 'vue'
import type { DocsearchOptions } from '../../shared/index.js'
import { useDocsearchShim } from '../composables/index.js'

import '@docsearch/css'
import '../styles/docsearch.css'
declare const __DOCSEARCH_INJECT_STYLES__: boolean

if (__DOCSEARCH_INJECT_STYLES__) {
import('@docsearch/css')
import('../styles/docsearch.css')
}

export const Docsearch = defineComponent({
name: 'Docsearch',
Expand Down
7 changes: 7 additions & 0 deletions ecosystem/plugin-docsearch/src/client/shims.d.ts
@@ -0,0 +1,7 @@
declare module '@docsearch/css' {
export {}
}

declare module '*.css' {
export {}
}
10 changes: 8 additions & 2 deletions ecosystem/plugin-docsearch/src/node/docsearchPlugin.ts
Expand Up @@ -4,14 +4,20 @@ import type { DocsearchOptions } from '../shared/index.js'

const __dirname = getDirname(import.meta.url)

export type DocsearchPluginOptions = DocsearchOptions
export interface DocsearchPluginOptions extends DocsearchOptions {
injectStyles?: boolean
}

export const docsearchPlugin = (options: DocsearchPluginOptions): Plugin => ({
export const docsearchPlugin = ({
injectStyles = true,
...options
}: DocsearchPluginOptions): Plugin => ({
name: '@vuepress/plugin-docsearch',

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

define: {
__DOCSEARCH_OPTIONS__: options,
__DOCSEARCH_INJECT_STYLES__: injectStyles,
},
})