load doc && demo in demand

This commit is contained in:
陈嘉涵
2017-08-09 16:19:45 +08:00
parent 4e57dfa797
commit 8ca524d9ac
8 changed files with 65 additions and 57 deletions

View File

@@ -1,4 +1,6 @@
const navs = require('./doc.config')['zh-CN'].nav;
import componentDocs from '../examples-dist/entry-docs';
import componentDemos from '../examples-dist/entry-demos';
const registerRoute = (isExample) => {
let route = [];
@@ -9,31 +11,26 @@ const registerRoute = (isExample) => {
if (nav.groups) {
nav.groups.forEach(group => {
group.list.forEach(nav => {
addRoute(nav);
});
group.list.forEach(addRoute);
});
} else if (nav.children) {
nav.children.forEach(nav => {
addRoute(nav);
});
nav.children.forEach(addRoute);
} else {
addRoute(nav);
}
});
function addRoute(page) {
const component = isExample
? require(`../examples-dist${page.path}.vue`)
: require(`../examples-docs${page.path}.md`);
route.push({
path: '/component' + page.path,
component: component.default || component
});
const { path } = page;
if (path) {
const name = path.replace('/', '');
route.push({
path: '/component' + path,
component: isExample ? componentDemos[name] : componentDocs[name]
});
}
}
// console.log(route);
return route;
};