forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd-loader-utils.js
More file actions
59 lines (54 loc) · 1.78 KB
/
md-loader-utils.js
File metadata and controls
59 lines (54 loc) · 1.78 KB
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
const matter = require('gray-matter')
const toml = require('toml')
function getComponentsImport (comp) {
return comp.map(c => {
const parts = c.split('/')
return `import ${parts[ parts.length - 1 ]} from 'components/page-parts/${c}.vue'\n`
}).join('')
}
function getComponentsDeclaration (comp) {
const list = comp.map(c => {
const parts = c.split('/')
return parts[ parts.length - 1 ]
}).join(',')
return `components: { ${list} },`
}
module.exports.getVueComponent = function (rendered, data, toc) {
return `
<template>
<doc-page
meta-title="${data.title}"
title="${data.heading !== false ? data.title : ''}"
${data.overline !== void 0 ? `overline="${data.overline}"` : ''}
${data.badge !== void 0 ? `badge="${data.badge}"` : ''}
${data.related !== void 0 ? ':related="related"' : ''}
${data.nav !== void 0 ? ':nav="nav"' : ''}
${data.related !== void 0 || data.nav !== void 0 ? ':toc="toc"' : ''}
${data.desc !== void 0 ? `meta-desc="${data.desc}"` : ''}>${rendered}</doc-page>
</template>
<script>
import { copyHeading } from 'assets/page-utils'
${data.components !== void 0 ? getComponentsImport(data.components) : ''}
export default {
name: 'DocMarkdownPage',
${data.components !== void 0 ? getComponentsDeclaration(data.components) : ''}
setup () {
return {
${data.related !== void 0 ? `related: ${JSON.stringify(data.related)},` : ''}
${data.nav !== void 0 ? `nav: ${JSON.stringify(data.nav)},` : ''}
${data.related !== void 0 || data.nav !== void 0 ? `toc: ${toc},` : ''}
copyHeading
}
}
}
</script>`
}
module.exports.parseFrontMatter = function (content) {
return matter(content, {
excerpt_separator: '<!-- more -->',
engines: {
toml: toml.parse.bind(toml),
excerpt: false
}
})
}