site: upgrade bisheng to 0.21.0

This commit is contained in:
Benjy Cui 2017-02-09 16:55:29 +08:00
parent ac23cca8b3
commit a950a1298a
4 changed files with 32 additions and 40 deletions

View File

@ -86,7 +86,7 @@
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"bisheng": "^0.20.0",
"bisheng": "^0.21.0",
"bisheng-plugin-antd": "^0.8.0",
"bisheng-plugin-description": "^0.1.1",
"bisheng-plugin-react": "^0.4.0",

View File

@ -2,12 +2,14 @@ const path = require('path');
module.exports = {
port: 8001,
source: [
'./components',
'./docs',
'CHANGELOG.zh-CN.md', // TODO: fix it in bisheng
'CHANGELOG.en-US.md',
],
source: {
components: './components',
docs: './docs',
changelog: [
'CHANGELOG.zh-CN.md',
'CHANGELOG.en-US.md',
],
},
theme: './site/theme',
htmlTemplate: './site/theme/static/template.html',
themeConfig: {

View File

@ -59,7 +59,6 @@ module.exports = {
childRoutes: [{
path: 'index-cn',
component: homeTmpl,
dataPath: '/',
}, {
path: 'docs/practice/:children',
component: contentTmpl,
@ -72,11 +71,9 @@ module.exports = {
}, {
path: 'changelog',
component: contentTmpl,
dataPath: 'CHANGELOG',
}, {
path: 'changelog-cn',
component: contentTmpl,
dataPath: 'CHANGELOG',
}, {
path: 'components/:children/',
component: contentTmpl,

View File

@ -1,36 +1,29 @@
import React from 'react';
import collect from 'bisheng/collect';
import MainContent from './MainContent';
import * as utils from '../utils';
export function collect(nextProps, callback) {
const pathname = nextProps.location.pathname;
const locale = utils.isZhCN(pathname) ? 'zh-CN' : 'en-US';
const pageDataPath = pathname.replace('-cn', '').split('/');
let pageData = nextProps.pageData;
if (!pageData && locale === 'zh-CN') {
pageData = nextProps.utils.get(nextProps.data, pageDataPath);
}
if (!pageData) {
callback(404, nextProps);
return;
}
const pageDataPromise = typeof pageData === 'function' ?
pageData() : (pageData[locale] || pageData.index[locale] || pageData.index)();
const promises = [pageDataPromise];
const demos = nextProps.utils.get(nextProps.data, [...pageDataPath, 'demo']);
if (demos) {
promises.push(demos());
}
Promise.all(promises)
.then(list => callback(null, {
...nextProps,
localizedPageData: list[0],
demos: list[1],
}));
function isChangelog(pathname) {
return pathname.indexOf('changelog') >= 0;
}
export default (props) => {
return <MainContent {...props} />;
};
export default collect(async (nextProps) => {
const pathname = nextProps.location.pathname;
const pageDataPath = pathname.replace('-cn', '').split('/');
const pageData = isChangelog(pathname) ?
nextProps.data.changelog.CHANGELOG :
nextProps.utils.get(nextProps.data, pageDataPath);
if (!pageData) {
throw 404;
}
const locale = utils.isZhCN(pathname) ? 'zh-CN' : 'en-US';
const pageDataPromise = typeof pageData === 'function' ?
pageData() : (pageData[locale] || pageData.index[locale] || pageData.index)();
const demosFetcher = nextProps.utils.get(nextProps.data, [...pageDataPath, 'demo']);
if (demosFetcher) {
const [ localizedPageData, demos ] = await Promise.all([pageDataPromise, demosFetcher()]);
return { localizedPageData, demos }
}
return { localizedPageData: await pageDataPromise };
})(MainContent);