/
Documentation.vue
116 lines (100 loc) 路 2.28 KB
/
Documentation.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<v-container
class="pa-4 pa-sm-6 pa-md-8"
tag="section"
>
<v-responsive
class="mx-auto overflow-visible"
max-width="868"
>
<keep-alive
max="3"
>
<component :is="component" />
</keep-alive>
</v-responsive>
</v-container>
</template>
<script>
// Utilities
import { IN_BROWSER } from '@/util/globals'
import { genMetaData } from '@/util/metadata'
import { get, sync } from 'vuex-pathify'
import { localeLookup } from '@/i18n/util'
async function load (route) {
const { category, page } = route.params
const isApi = category === 'api'
const locale = localeLookup(route.params.locale)
const context = isApi
? await import(
/* webpackChunkName: "api-[request]" */
`@/api/${locale}.js`
)
: await import(
/* webpackChunkName: "documentation-[request]" */
`@/pages/${locale}.js`
)
const path = ['.']
if (!isApi) path.push(category)
path.push(page)
return context.default(`${path.join('/')}.md`)
}
export default {
name: 'DocumentationView',
async asyncData ({ route, store }) {
const md = await load(route)
store.state.pages.md = md
},
metaInfo () {
if (!this.frontmatter) return {}
const { meta } = this.frontmatter
if (!meta) return
const {
description = '',
keywords = '',
title = '',
} = meta
return genMetaData(
title,
description,
keywords,
)
},
data: () => ({
component: undefined,
}),
computed: {
...sync('pages', [
'frontmatter',
'toc',
'md',
]),
...get('route', [
'hash',
'params@page',
]),
},
async created () {
if (IN_BROWSER && !this.$vuetify.isHydrating) {
await this.$options.asyncData({
route: this.$route,
store: this.$store,
})
}
this.init(this.md)
},
methods: {
init (md) {
const {
attributes = {},
toc = [],
vue = {},
} = md
vue.component.name = this.page
this.frontmatter = attributes
this.toc = toc
this.component = vue.component
},
},
}
</script>