mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
docs: dynamically generate sidebar navigation
This commit is contained in:
@@ -64,7 +64,7 @@ module.exports = {
|
|||||||
description: meta.description,
|
description: meta.description,
|
||||||
head,
|
head,
|
||||||
plugins: [
|
plugins: [
|
||||||
require('./generateApiDocs'),
|
require('./generateApiDocs/index'),
|
||||||
['@vuepress/google-analytics',{ga: isDeployPreview ? '' : 'UA-12818324-8',}],
|
['@vuepress/google-analytics',{ga: isDeployPreview ? '' : 'UA-12818324-8',}],
|
||||||
['@vuepress/pwa', {
|
['@vuepress/pwa', {
|
||||||
serviceWorker: false,
|
serviceWorker: false,
|
||||||
@@ -130,15 +130,6 @@ module.exports = {
|
|||||||
['guide/keydown', 'Keydown Events'],
|
['guide/keydown', 'Keydown Events'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: 'API',
|
|
||||||
collapsable: false,
|
|
||||||
children: [
|
|
||||||
['api/props', 'Props'],
|
|
||||||
['api/slots', 'Slots'],
|
|
||||||
['api/events', 'Events'],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
const docs = require('vue-docgen-api');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an object of API documentation.
|
||||||
|
* @param documentationRootDir
|
||||||
|
* @return {Promise<ComponentDoc>}
|
||||||
|
*/
|
||||||
|
module.exports = async (documentationRootDir) => {
|
||||||
|
const file = path.resolve(documentationRootDir, '../src/components/Select.vue');
|
||||||
|
return await docs.parse(file);
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const docs = require('vue-docgen-api');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const generator = require('./generator');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all of the component mixin paths.
|
* Get all of the component mixin paths.
|
||||||
@@ -30,11 +30,12 @@ module.exports = (options, {sourceDir}) => ({
|
|||||||
* @return {Promise<{name: string, content: string}>}
|
* @return {Promise<{name: string, content: string}>}
|
||||||
*/
|
*/
|
||||||
async clientDynamicModules () {
|
async clientDynamicModules () {
|
||||||
const file = path.resolve(sourceDir, '../src/components/Select.vue');
|
const docs = await generator(sourceDir);
|
||||||
|
console.log('Generated API documentation for Select.vue');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'api.js',
|
name: 'api.js',
|
||||||
content: `export default ${JSON.stringify(await docs.parse(file))}`,
|
content: `export default ${JSON.stringify(docs)}`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<template>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<section class="sidebar-group depth-0">
|
||||||
|
<p class="sidebar-heading open"><span>API</span></p>
|
||||||
|
<ul class="sidebar-links sidebar-group-items">
|
||||||
|
<li v-for="section in docs">
|
||||||
|
<router-link
|
||||||
|
:to="section.url"
|
||||||
|
:class="linkClass(section.url)"
|
||||||
|
>
|
||||||
|
{{ section.title }}
|
||||||
|
</router-link>
|
||||||
|
|
||||||
|
<ul v-if="section.active" class="sidebar-sub-headers">
|
||||||
|
<li v-for="link in section.links" :key="link" class="sidebar-sub-header">
|
||||||
|
<router-link
|
||||||
|
:to="`${section.url}#${link}`"
|
||||||
|
:class="linkClass(`${section.url}#${link}`)"
|
||||||
|
>
|
||||||
|
{{ link }}
|
||||||
|
</router-link>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { isActive } from '@vuepress/theme-default/util'
|
||||||
|
import documentation from '@dynamic/api'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "SideBarApi",
|
||||||
|
methods: {
|
||||||
|
isActive,
|
||||||
|
linkClass (path) {
|
||||||
|
return {
|
||||||
|
'active': isActive(this.$route, path),
|
||||||
|
'sidebar-link': true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
docs () {
|
||||||
|
return ['Props', 'Events', 'Slots'].map(section => {
|
||||||
|
const lowercase = section.toLowerCase();
|
||||||
|
return {
|
||||||
|
title: section,
|
||||||
|
url: `/api/${lowercase}.html`,
|
||||||
|
links: documentation[lowercase].map(({name}) => name).sort(),
|
||||||
|
active: this.isActive(this.$route, `/api/${lowercase}.html`),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
ul {
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<ParentLayout>
|
<ParentLayout>
|
||||||
<CodeFund slot="sidebar-top"/>
|
<CodeFund slot="sidebar-top" />
|
||||||
|
<SideBarApi slot="sidebar-bottom" />
|
||||||
</ParentLayout>
|
</ParentLayout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ParentLayout from '@parent-theme/layouts/Layout.vue'
|
import ParentLayout from '@parent-theme/layouts/Layout.vue'
|
||||||
import CodeFund from '../components/CodeFund.vue'
|
import CodeFund from '../components/CodeFund.vue'
|
||||||
|
import SideBarApi from '../components/SideBarApi.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
ParentLayout,
|
ParentLayout,
|
||||||
CodeFund
|
CodeFund,
|
||||||
|
SideBarApi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -23,5 +26,7 @@ export default {
|
|||||||
}
|
}
|
||||||
#codefund + .sidebar-links {
|
#codefund + .sidebar-links {
|
||||||
padding-top: 1rem;
|
padding-top: 1rem;
|
||||||
|
border-bottom: none;
|
||||||
|
padding-bottom: 0.75rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user