feat: add demo edit link

This commit is contained in:
Justineo
2021-10-25 20:18:05 +08:00
parent e69f8fcc3c
commit a3d118cdbd
4 changed files with 72 additions and 28 deletions

View File

@@ -8,14 +8,15 @@ export default function attacher () {
let { tagName } = node
let [name] = tagName.match(RE_DEMO) || []
if (name) {
let { code, desc, browser } = data.demos[name] || {}
let { code, desc, browser, path } = data.demos[name] || {}
if (!code) {
return
}
let demo = h('one-demo',
{
browser
browser,
path
},
[
node,

View File

@@ -40,6 +40,8 @@ export default function attacher () {
? resolve(DOCS_DIR, src.slice(1))
: resolve(dirname(path), src)
let demoRelativePath = relative(DOCS_DIR, demoPath)
if (!existsSync(demoPath)) {
console.warn(`Demo not found at '${demoPath}'`)
return
@@ -55,7 +57,8 @@ export default function attacher () {
let { content, doc } = extractDoc(demoPath, { locale })
fileData.demos[name] = {
path: demoPath,
filePath: demoPath,
path: demoRelativePath,
browser,
code: render('```vue\n' + content + '\n```', demoPath).contents,
desc: render(doc, demoPath).contents