Skip to content

Commit

Permalink
feat($core): make palette globally enabled and improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Sep 28, 2018
1 parent 19e73d7 commit 2b2e308
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 30 deletions.
20 changes: 17 additions & 3 deletions packages/@vuepress/core/lib/internal-plugins/palette/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
fs, logger,
fs, path, logger,
datatypes: {
isPlainObject,
assertTypes,
Expand All @@ -11,15 +11,29 @@ module.exports = (options, ctx) => ({
name: '@vuepress/internal-palette',

async ready () {
const { writeTemp } = ctx
// 1. enable config.styl globally.
const configFile = path.resolve(__dirname, '../../app/style/config.styl')
if (!ctx.siteConfig.stylus) {
ctx.siteConfig.stylus = {
import: [configFile]
}
} else if (isPlainObject(ctx.siteConfig.stylus)) {
ctx.siteConfig.stylus.import = (ctx.siteConfig.stylus.import || []).concat([configFile])
}

// 2. write palette.styl
const { sourceDir, writeTemp } = ctx

const themePalette = ctx.themePalette
const { palette: userPalette } = ctx.siteConfig
const palettePath = path.resolve(sourceDir, '.vuepress/palette.styl')

const themePaletteContent = resolvePaletteContent(themePalette)
const userPaletteContent = resolvePaletteContent(userPalette)
const userPaletteContent2 = resolvePaletteContent(palettePath)

// user's palette can override theme's palette.
const paletteContent = themePaletteContent + userPaletteContent
const paletteContent = themePaletteContent + userPaletteContent + userPaletteContent2
await writeTemp('palette.styl', paletteContent)
}
})
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/core/lib/internal-plugins/style/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
// generated from user config
import('@temp/style.styl')

window.__VUEPRESS_STYLE_STYLE_LOADED__ = true
2 changes: 0 additions & 2 deletions packages/@vuepress/plugin-search/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ export default {
</script>

<style lang="stylus">
@import '~@app/style/config'
.search-box
display inline-block
position relative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export default {
</script>

<style lang="stylus">
@import '~@app/style/config'
.algolia-search-wrapper
& > span
vertical-align middle
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/Badge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export default {
</script>

<style lang="stylus" scoped>
@import '~@app/style/config'
.badge
display inline-block
font-size 14px
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/DropdownLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export default {
</script>

<style lang="stylus">
@import '~@app/style/config'
.dropdown-wrapper
cursor pointer
.dropdown-title
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export default {
</script>

<style lang="stylus">
@import '~@app/style/config'
.home
padding $navbarHeight 2rem 0
max-width 960px
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/NavLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ export default {
</script>

<style lang="stylus">
@import '~@app/style/config'
.nav-links
display inline-block
a
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ function css (el, property) {
</script>

<style lang="stylus">
@import '~@app/style/config'
$navbar-vertical-padding = 0.7rem
$navbar-horizontal-padding = 1.5rem
Expand Down
1 change: 0 additions & 1 deletion packages/@vuepress/theme-default/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ function find (page, items, offset) {
</script>

<style lang="stylus">
@import '~@app/style/config'
@require '../styles/wrapper.styl'
.page
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ function resolveOpenGroupIndex (route, items) {
</script>

<style lang="stylus">
@import '~@app/style/config'
.sidebar
ul
padding 0
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/SidebarButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
</template>

<style lang="stylus">
@import '~@app/style/config'
.sidebar-button
display none
width 1.25rem
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/components/SidebarLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ function renderChildren (h, children, path, route, maxDepth, depth = 1) {
</script>

<style lang="stylus">
@import '~@app/style/config'
.sidebar .sidebar-sub-headers
padding-left 1rem
font-size 0.95em
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/styles/code.styl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import '~@app/style/config'

.content
code
color lighten($textColor, 20%)
Expand Down
1 change: 0 additions & 1 deletion packages/@vuepress/theme-default/styles/theme.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@require '~@app/style/config'
@require './nprogress'
@require './code'
@require './custom-blocks'
Expand Down
64 changes: 64 additions & 0 deletions packages/docs/docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,57 @@ Specify locales for i18n support. For more details, see the guide on [Internatio

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

## Styling

### palette

- Type: `Object|String`
- Default: `undefined`

Set globally available stylus color variables.

If it is string, it needs to be a **absolute path** pointing to a stylus file that defines the color constant:

```js
module.exports = {
palette: path.resolve(__dirname, 'palette.styl'),
}
```

::: tip
When `config.palette` is empty, vuepress will detect whether `.vuepress/palette.styl` exists. If it exists, the file will be used as palette.
:::

If it is an object, it needs to be an object with key as the color name and value as the HEX color value.

```js
module.exports = {
palette: {
// Internal default color constants can be
// modified to quickly modify global styles.
$accentColor: '#3eaf7c',
$textColor: '#2c3e50',
$borderColor: '#eaecef',
$codeBgColor: '#282c34',
$arrowBgColor: '#ccc',

// Your extra colors
$shadowColor: '#ddd'
}
}
```

::: tip
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).
:::

### style

- Type: `string`
- Default: `undefined`

TODO

## Theming

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

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

## Pluggable

### plugins

- Type: `Object|Array`
- Default: `undefined`

For default usage, please refer to [plugin API](../plugin/README.md).

::: tip
There is a hidden feature. `.vuepress/config.js` also supports all [options](../plugin/README.md#options) plugin API.
:::

## Markdown

### markdown.lineNumbers
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/docs/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ You should ONLY write color variables in this file. since `palette.styl` will be
VuePress provides a convenient way to add extra styles. you can create an `.vuepress/style.styl` file for that:

```stylus
content {
.content {
font-size 30px
}
```
Expand Down

0 comments on commit 2b2e308

Please sign in to comment.