Skip to content

Commit 2b2e308

Browse files
committed
feat($core): make palette globally enabled and improve doc
1 parent 19e73d7 commit 2b2e308

File tree

17 files changed

+82
-30
lines changed

17 files changed

+82
-30
lines changed

packages/@vuepress/core/lib/internal-plugins/palette/index.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {
2-
fs, logger,
2+
fs, path, logger,
33
datatypes: {
44
isPlainObject,
55
assertTypes,
@@ -11,15 +11,29 @@ module.exports = (options, ctx) => ({
1111
name: '@vuepress/internal-palette',
1212

1313
async ready () {
14-
const { writeTemp } = ctx
14+
// 1. enable config.styl globally.
15+
const configFile = path.resolve(__dirname, '../../app/style/config.styl')
16+
if (!ctx.siteConfig.stylus) {
17+
ctx.siteConfig.stylus = {
18+
import: [configFile]
19+
}
20+
} else if (isPlainObject(ctx.siteConfig.stylus)) {
21+
ctx.siteConfig.stylus.import = (ctx.siteConfig.stylus.import || []).concat([configFile])
22+
}
23+
24+
// 2. write palette.styl
25+
const { sourceDir, writeTemp } = ctx
1526

1627
const themePalette = ctx.themePalette
1728
const { palette: userPalette } = ctx.siteConfig
29+
const palettePath = path.resolve(sourceDir, '.vuepress/palette.styl')
30+
1831
const themePaletteContent = resolvePaletteContent(themePalette)
1932
const userPaletteContent = resolvePaletteContent(userPalette)
33+
const userPaletteContent2 = resolvePaletteContent(palettePath)
2034

2135
// user's palette can override theme's palette.
22-
const paletteContent = themePaletteContent + userPaletteContent
36+
const paletteContent = themePaletteContent + userPaletteContent + userPaletteContent2
2337
await writeTemp('palette.styl', paletteContent)
2438
}
2539
})
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
// generated from user config
22
import('@temp/style.styl')
3-
4-
window.__VUEPRESS_STYLE_STYLE_LOADED__ = true

packages/@vuepress/plugin-search/SearchBox.vue

-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ export default {
153153
</script>
154154

155155
<style lang="stylus">
156-
@import '~@app/style/config'
157-
158156
.search-box
159157
display inline-block
160158
position relative

packages/@vuepress/theme-default/components/AlgoliaSearchBox.vue

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ export default {
5959
</script>
6060

6161
<style lang="stylus">
62-
@import '~@app/style/config'
63-
6462
.algolia-search-wrapper
6563
& > span
6664
vertical-align middle

packages/@vuepress/theme-default/components/Badge.vue

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export default {
2121
</script>
2222

2323
<style lang="stylus" scoped>
24-
@import '~@app/style/config'
25-
2624
.badge
2725
display inline-block
2826
font-size 14px

packages/@vuepress/theme-default/components/DropdownLink.vue

-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ export default {
7777
</script>
7878

7979
<style lang="stylus">
80-
@import '~@app/style/config'
81-
8280
.dropdown-wrapper
8381
cursor pointer
8482
.dropdown-title

packages/@vuepress/theme-default/components/Home.vue

-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ export default {
7171
</script>
7272

7373
<style lang="stylus">
74-
@import '~@app/style/config'
75-
7674
.home
7775
padding $navbarHeight 2rem 0
7876
max-width 960px

packages/@vuepress/theme-default/components/NavLinks.vue

-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ export default {
116116
</script>
117117

118118
<style lang="stylus">
119-
@import '~@app/style/config'
120-
121119
.nav-links
122120
display inline-block
123121
a

packages/@vuepress/theme-default/components/Navbar.vue

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ function css (el, property) {
8686
</script>
8787

8888
<style lang="stylus">
89-
@import '~@app/style/config'
90-
9189
$navbar-vertical-padding = 0.7rem
9290
$navbar-horizontal-padding = 1.5rem
9391

packages/@vuepress/theme-default/components/Page.vue

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ function find (page, items, offset) {
195195
</script>
196196

197197
<style lang="stylus">
198-
@import '~@app/style/config'
199198
@require '../styles/wrapper.styl'
200199
201200
.page

packages/@vuepress/theme-default/components/Sidebar.vue

-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ function resolveOpenGroupIndex (route, items) {
7979
</script>
8080

8181
<style lang="stylus">
82-
@import '~@app/style/config'
83-
8482
.sidebar
8583
ul
8684
padding 0

packages/@vuepress/theme-default/components/SidebarButton.vue

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
</template>
88

99
<style lang="stylus">
10-
@import '~@app/style/config'
11-
1210
.sidebar-button
1311
display none
1412
width 1.25rem

packages/@vuepress/theme-default/components/SidebarLink.vue

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ function renderChildren (h, children, path, route, maxDepth, depth = 1) {
5959
</script>
6060

6161
<style lang="stylus">
62-
@import '~@app/style/config'
63-
6462
.sidebar .sidebar-sub-headers
6563
padding-left 1rem
6664
font-size 0.95em

packages/@vuepress/theme-default/styles/code.styl

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import '~@app/style/config'
2-
31
.content
42
code
53
color lighten($textColor, 20%)

packages/@vuepress/theme-default/styles/theme.styl

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@require '~@app/style/config'
21
@require './nprogress'
32
@require './code'
43
@require './custom-blocks'

packages/docs/docs/config/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,57 @@ Specify locales for i18n support. For more details, see the guide on [Internatio
118118

119119
A function to control what files should have `<link rel="preload">` resource hints generated. See [shouldPrefetch](https://ssr.vuejs.org/api/#shouldprefetch).
120120

121+
## Styling
122+
123+
### palette
124+
125+
- Type: `Object|String`
126+
- Default: `undefined`
127+
128+
Set globally available stylus color variables.
129+
130+
If it is string, it needs to be a **absolute path** pointing to a stylus file that defines the color constant:
131+
132+
```js
133+
module.exports = {
134+
palette: path.resolve(__dirname, 'palette.styl'),
135+
}
136+
```
137+
138+
::: tip
139+
When `config.palette` is empty, vuepress will detect whether `.vuepress/palette.styl` exists. If it exists, the file will be used as palette.
140+
:::
141+
142+
If it is an object, it needs to be an object with key as the color name and value as the HEX color value.
143+
144+
```js
145+
module.exports = {
146+
palette: {
147+
// Internal default color constants can be
148+
// modified to quickly modify global styles.
149+
$accentColor: '#3eaf7c',
150+
$textColor: '#2c3e50',
151+
$borderColor: '#eaecef',
152+
$codeBgColor: '#282c34',
153+
$arrowBgColor: '#ccc',
154+
155+
// Your extra colors
156+
$shadowColor: '#ddd'
157+
}
158+
}
159+
```
160+
161+
::: tip
162+
It is worth noting that `modifying global style` via `palette` depends on the strict use of the default palette for your theme (e.g. the `@vuepress/theme-default` you see now).
163+
:::
164+
165+
### style
166+
167+
- Type: `string`
168+
- Default: `undefined`
169+
170+
TODO
171+
121172
## Theming
122173

123174
### theme
@@ -138,6 +189,19 @@ Provide config options to the used theme. The options will vary depending on the
138189

139190
- [Default Theme Configuration](../default-theme-config/README.md).
140191

192+
## Pluggable
193+
194+
### plugins
195+
196+
- Type: `Object|Array`
197+
- Default: `undefined`
198+
199+
For default usage, please refer to [plugin API](../plugin/README.md).
200+
201+
::: tip
202+
There is a hidden feature. `.vuepress/config.js` also supports all [options](../plugin/README.md#options) plugin API.
203+
:::
204+
141205
## Markdown
142206

143207
### markdown.lineNumbers

packages/docs/docs/default-theme-config/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ You should ONLY write color variables in this file. since `palette.styl` will be
459459
VuePress provides a convenient way to add extra styles. you can create an `.vuepress/style.styl` file for that:
460460

461461
```stylus
462-
content {
462+
.content {
463463
font-size 30px
464464
}
465465
```

0 commit comments

Comments
 (0)