feat(core): add userStyle option to ensure highest css priority (clos… · vuepress/core@071cc21 · GitHub
Skip to content

Commit 071cc21

Browse files
feat(core): add userStyle option to ensure highest css priority (close #1110) (#1695)
Co-authored-by: Xinyu Liu <meteor.lxy@foxmail.com>
1 parent 3140c3c commit 071cc21

14 files changed

Lines changed: 101 additions & 0 deletions

packages/core/src/app/prepare/prepareClientConfigs.ts

Lines changed: 1 addition & 0 deletions

packages/core/src/app/resolveAppOptions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const resolveAppOptions = ({
4545
markdown = {},
4646
pagePatterns = ['**/*.md', '!.vuepress'],
4747
permalinkPattern = null,
48+
userStyle = null,
4849
plugins = [],
4950
theme,
5051
}: AppConfig): AppOptions => {
@@ -76,6 +77,7 @@ export const resolveAppOptions = ({
7677
markdown,
7778
pagePatterns,
7879
permalinkPattern,
80+
userStyle,
7981
plugins,
8082
theme,
8183
}

packages/core/src/app/resolveThemeInfo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const resolveThemeInfo = (app: App, theme: Theme): ThemeInfo => {
1414
templateBuild: themeObject.templateBuild,
1515
templateBuildRenderer: themeObject.templateBuildRenderer,
1616
templateDev: themeObject.templateDev,
17+
userStyle: themeObject.userStyle,
1718
}
1819

1920
// return if current theme does not have a parent theme
@@ -30,5 +31,6 @@ export const resolveThemeInfo = (app: App, theme: Theme): ThemeInfo => {
3031
themeObject.templateBuildRenderer ??
3132
parentThemeInfo.templateBuildRenderer,
3233
templateDev: themeObject.templateDev ?? parentThemeInfo.templateDev,
34+
userStyle: themeObject.userStyle ?? parentThemeInfo.userStyle,
3335
}
3436
}

packages/core/src/app/setupAppThemeAndPlugins.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { resolveThemeInfo } from './resolveThemeInfo.js'
99
export const setupAppThemeAndPlugins = (app: App, config: AppConfig): void => {
1010
// recursively resolve theme info
1111
const themeInfo = resolveThemeInfo(app, app.options.theme)
12+
1213
// set up app templates
1314
app.options.templateDev =
1415
config.templateDev ?? themeInfo.templateDev ?? app.options.templateDev
@@ -18,6 +19,11 @@ export const setupAppThemeAndPlugins = (app: App, config: AppConfig): void => {
1819
config.templateBuildRenderer ??
1920
themeInfo.templateBuildRenderer ??
2021
app.options.templateBuildRenderer
22+
23+
// set up user style
24+
app.options.userStyle =
25+
config.userStyle ?? themeInfo.userStyle ?? app.options.userStyle
26+
2127
// use options plugins after theme plugins, allowing user to override theme plugins
2228
;[...themeInfo.plugins, ...app.options.plugins]
2329
.flat()

packages/core/src/types/app/options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export interface AppConfigCommon extends Partial<SiteData> {
8383
*/
8484
permalinkPattern?: string | null
8585

86+
/**
87+
* Allow specifying user styles, which will be injected into client at the bottom
88+
*/
89+
userStyle?: string | null
90+
8691
/**
8792
* Vuepress bundler
8893
*

packages/core/src/types/theme.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export interface ThemeObject extends Omit<PluginObject, 'multiple'> {
5151
* Allow overriding default templateDev
5252
*/
5353
templateDev?: string
54+
55+
/**
56+
* Allow specifying user styles, which will be injected into client at the bottom
57+
*/
58+
userStyle?: string
5459
}
5560

5661
/**
@@ -76,4 +81,9 @@ export interface ThemeInfo {
7681
* Default dev template
7782
*/
7883
templateDev?: string
84+
85+
/**
86+
* Allow specifying user styles, which will be injected into client at the bottom
87+
*/
88+
userStyle?: string
7989
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import funcUserStyleParent from './func-user-style-parent.js'
2+
3+
export default () => ({
4+
name: 'theme-func-user-style-child-inherit',
5+
extends: funcUserStyleParent(),
6+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import funcUserStyleParent from './func-user-style-parent.js'
2+
3+
export default () => ({
4+
name: 'theme-func-user-style-child-override',
5+
extends: funcUserStyleParent(),
6+
userStyle: 'child-user-style-override',
7+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default () => ({
2+
name: 'theme-func-user-style-parent',
3+
userStyle: 'parent-user-style',
4+
})
Lines changed: 6 additions & 0 deletions

0 commit comments

Comments
 (0)