Skip to content

Commit d16d3d5

Browse files
authored
feat: refine theme api (#1319)
1 parent 40b3da8 commit d16d3d5

File tree

47 files changed

+1012
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1012
-397
lines changed

β€ŽCHANGELOG.md

100644100755
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,6 @@
2222
### Features
2323

2424
* **$core:** support global layout (close: [#1226](https://github.com/vuejs/vuepress/issues/1226)) ([c91f55a](https://github.com/vuejs/vuepress/commit/c91f55a))
25-
26-
From now on, users have the ability to use a custom global layout component via [siteConfig](https://v1.vuepress.vuejs.org/miscellaneous/glossary.html#siteconfig) or [themeEntryFile](https://v1.vuepress.vuejs.org/miscellaneous/glossary.html#themeentryfile):
27-
28-
```js
29-
module.exports = {
30-
globalLayout: '/path/to/your/global/vue/sfc'
31-
}
32-
```
33-
34-
Here is the [content of default global layout component](https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/core/lib/app/components/GlobalLayout.vue), an example of setting global header and footer:
35-
36-
```vue
37-
<template>
38-
<div id="global-layout">
39-
<header><h1>Header</h1></header>
40-
<component :is="layout"/>
41-
<footer><h1>Footer</h1></footer>
42-
</div>
43-
</template>
44-
45-
<script>
46-
export default {
47-
computed: {
48-
layout () {
49-
if (this.$page.path) {
50-
if (this.$vuepress.isLayoutExists(this.$page.frontmatter.layout)) {
51-
return this.$page.frontmatter.layout
52-
}
53-
return 'Layout'
54-
}
55-
return 'NotFound'
56-
}
57-
}
58-
}
59-
</script>
60-
```
61-
62-
Also, you can follow the convention, directly create a component `.vuepress/components/GlobalLayout.vue` or `themePath/layouts/GlobalLayout.vue` without any config. the loading priority is as follows:
63-
64-
- siteConfig
65-
- siteAgreement
66-
- themeEntryFile
67-
- themeAgreement
68-
- default
69-
7025
* **$theme-default:** disable search box via frontmatter (close: [#1287](https://github.com/vuejs/vuepress/issues/1287)) ([#1288](https://github.com/vuejs/vuepress/issues/1288)) ([54e9eb0](https://github.com/vuejs/vuepress/commit/54e9eb0))
7126

7227

β€Ž__mocks__/vuepress-theme-child/Layout.vue

Whitespace-only changes.

β€Ž__mocks__/vuepress-theme-child/components/Home.vue

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extend: 'vuepress-theme-parent'
3+
}

β€Ž__mocks__/vuepress-theme-parent/Layout.vue

Whitespace-only changes.

β€Ž__mocks__/vuepress-theme-parent/components/Home.vue

Whitespace-only changes.

β€Ž__mocks__/vuepress-theme-parent/components/Sidebar.vue

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}

β€Žpackages/@vuepress/core/__tests__/theme-api/fixtures/theme/Layout.vue

Whitespace-only changes.

β€Žpackages/@vuepress/core/__tests__/theme-api/fixtures/theme/components/Home.vue

Whitespace-only changes.

0 commit comments

Comments
Β (0)