docs: auto detect languages from demo main file

This commit is contained in:
Hans Pagel 2021-02-11 16:11:33 +01:00
parent 4ed025e210
commit 30fccac47c
4 changed files with 21 additions and 19 deletions

View File

@ -23,11 +23,6 @@ export default {
required: true, required: true,
}, },
mode: {
type: String,
default: 'vue',
},
inline: { inline: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -52,7 +47,7 @@ export default {
computed: { computed: {
query() { query() {
return `mode=${this.mode}&inline=${this.inline}&highlight=${this.highlight}&showSource=${this.showSource}` return `inline=${this.inline}&highlight=${this.highlight}&showSource=${this.showSource}`
}, },
}, },

View File

@ -7,11 +7,6 @@ export default {
required: true, required: true,
}, },
mode: {
type: String,
default: 'vue',
},
inline: { inline: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -41,7 +36,6 @@ export default {
props() { props() {
return { return {
name: this.name, name: this.name,
mode: this.mode,
inline: this.inline, inline: this.inline,
highlight: this.highlight, highlight: this.highlight,
showSource: this.showSource, showSource: this.showSource,
@ -49,14 +43,27 @@ export default {
}, },
mainFile() { mainFile() {
const file = this.files if (!this.mainFilePath) {
.find(item => item.path.endsWith('index.vue') || item.path.endsWith('index.jsx'))
if (!file) {
return false return false
} }
return require(`~/demos/${file.path}`).default return require(`~/demos/${this.mainFilePath}`).default
},
mainFilePath() {
const file = this.files.find(item => item.path.endsWith('index.vue') || item.path.endsWith('index.jsx'))
if (file) {
return file.path
}
},
mode() {
if (this.mainFilePath?.endsWith('.jsx')) {
return 'react'
}
return 'vue'
}, },
}, },

View File

@ -7,4 +7,4 @@ The following guide describes how to integrate tiptap with your [Next.js](https:
TODO TODO
<demo name="React" mode="react" /> <demo name="React" />

View File

@ -7,4 +7,4 @@ The following guide describes how to integrate tiptap with your [React](https://
TODO TODO
<demo name="React" mode="react" /> <demo name="React" />