Skip to content

Commit 216d04a

Browse files
committed
feat: built-in content loading
1 parent 985471b commit 216d04a

File tree

7 files changed

+120
-37
lines changed

7 files changed

+120
-37
lines changed

packages/@vuepress/core/lib/app/components/Content.js

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<template>
2+
<component :is="layout" :slot-key="slotKey || 'default'"/>
3+
</template>
4+
5+
<script>
6+
import Vue from 'vue'
7+
import components from '@internal/page-components'
8+
import ContentLoading from './ContentLoading'
9+
10+
export default {
11+
components: { ContentLoading },
12+
13+
props: {
14+
pageKey: String,
15+
slotKey: String
16+
},
17+
18+
data () {
19+
return {
20+
layout: 'ContentLoading'
21+
}
22+
},
23+
24+
computed: {
25+
$key () {
26+
return this.pageKey || this.$page.key
27+
}
28+
},
29+
30+
created () {
31+
this.loadContent(this.$key)
32+
},
33+
34+
watch: {
35+
$key (key) {
36+
this.loadContent(key)
37+
}
38+
},
39+
40+
methods: {
41+
loadContent (pageKey) {
42+
if (Vue.component(pageKey)) {
43+
return
44+
}
45+
this.layout = 'ContentLoading'
46+
if (components[pageKey]) {
47+
if (!this.$ssrContext) {
48+
Promise.all([
49+
components[pageKey](),
50+
new Promise(resolve => setTimeout(resolve, 0))
51+
]).then(([comp]) => {
52+
this.$vuepress.$emit('AsyncMarkdownAssetLoaded', this.pageKey)
53+
Vue.component(pageKey, comp.default)
54+
this.layout = pageKey
55+
})
56+
}
57+
}
58+
}
59+
}
60+
}
61+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<template>
2+
<div class="content content-loading">
3+
<ContentLoader
4+
:height="120"
5+
:width="300"
6+
:speed="0.5"
7+
primaryColor="#f3f3f3"
8+
secondaryColor="#ecebeb"
9+
>
10+
<rect x="0" y="5" rx="5" ry="5" width="117" height="10"/>
11+
<rect x="0" y="25" rx="5" ry="5" width="85" height="10"/>
12+
<rect x="0" y="60" rx="5" ry="5" width="250" height="10"/>
13+
<rect x="0" y="80" rx="5" ry="5" width="280" height="10"/>
14+
<rect x="0" y="100" rx="5" ry="5" width="201" height="10"/>
15+
</ContentLoader>
16+
</div>
17+
</template>
18+
19+
<script>
20+
import { ContentLoader } from 'vue-content-loader'
21+
22+
export default {
23+
components: {
24+
ContentLoader
25+
},
26+
27+
data () {
28+
return {
29+
containerStyle: {}
30+
}
31+
}
32+
}
33+
</script>
34+
35+
<style>
36+
@media screen and (min-width: 719px) {
37+
.content.content-loading > svg {
38+
max-width: 400px !important;
39+
}
40+
}
41+
@media screen and (max-width: 719px) {
42+
.content.content-loading > svg {
43+
max-width: 320px !important;
44+
}
45+
}
46+
47+
</style>

packages/@vuepress/core/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"webpack-chain": "^4.6.0",
6868
"webpack-merge": "^4.1.2",
6969
"webpack-serve": "^1.0.2",
70-
"webpackbar": "^2.6.1"
70+
"webpackbar": "^2.6.1",
71+
"vue-content-loader": "^0.2.1"
7172
},
7273
"engines": {
7374
"node": ">=8"

packages/docs/docs/guide/markdown-slot.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ Suppose your layout component is as follows:
4444
<template>
4545
<div class="container">
4646
<header>
47-
<Content slot="header"/>
47+
<Content slot-key="header"/>
4848
</header>
4949
<main>
5050
<Content/>
5151
</main>
5252
<footer>
53-
<Content slot="footer"/>
53+
<Content slot-key="footer"/>
5454
</footer>
5555
</div>
5656
</template>

packages/docs/docs/zh/guide/markdown-slot.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ Markdown 插槽便是为了解决这一类问题。
4444
<template>
4545
<div class="container">
4646
<header>
47-
<Content slot="header"/>
47+
<Content slot-key="header"/>
4848
</header>
4949
<main>
5050
<Content/>
5151
</main>
5252
<footer>
53-
<Content slot="footer"/>
53+
<Content slot-key="footer"/>
5454
</footer>
5555
</div>
5656
</template>

yarn.lock

+6
Original file line numberDiff line numberDiff line change
@@ -9045,6 +9045,12 @@ [email protected]:
90459045
dependencies:
90469046
indexof "0.0.1"
90479047

9048+
vue-content-loader@^0.2.1:
9049+
version "0.2.1"
9050+
resolved "https://registry.yarnpkg.com/vue-content-loader/-/vue-content-loader-0.2.1.tgz#0eb332e2a72643d57fb209d72d6526573b191f5a"
9051+
dependencies:
9052+
babel-helper-vue-jsx-merge-props "^2.0.3"
9053+
90489054
vue-eslint-parser@^2.0.3:
90499055
version "2.0.3"
90509056
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-2.0.3.tgz#c268c96c6d94cfe3d938a5f7593959b0ca3360d1"

0 commit comments

Comments
 (0)