ant-design/site/theme/template/Content/index.jsx

37 lines
1020 B
React
Raw Normal View History

import React from 'react';
2016-06-09 15:00:44 +08:00
import Promise from 'bluebird';
2016-08-23 21:00:35 +08:00
import MainContent from './MainContent';
import * as utils from '../utils';
2016-08-04 10:52:09 +08:00
const locale = utils.isZhCN() ? 'zh-CN' : 'en-US';
2016-06-09 15:00:44 +08:00
export function collect(nextProps, callback) {
const pageData = nextProps.location.pathname.endsWith('changelog') ?
2016-08-04 10:52:09 +08:00
nextProps.data.CHANGELOG : nextProps.pageData;
2016-09-20 16:48:34 +08:00
if (!pageData) {
callback(404, nextProps);
return;
}
2016-08-04 10:52:09 +08:00
const pageDataPromise = typeof pageData === 'function' ?
pageData() : (pageData[locale] || pageData.index[locale] || pageData.index)();
const promises = [pageDataPromise];
2016-06-09 15:00:44 +08:00
const pathname = nextProps.location.pathname;
2016-08-04 10:52:09 +08:00
const demos = nextProps.utils.get(
nextProps.data, [...pathname.split('/'), 'demo']
);
2016-06-09 15:00:44 +08:00
if (demos) {
2016-08-03 14:39:55 +08:00
promises.push(demos());
2016-06-09 15:00:44 +08:00
}
Promise.all(promises)
.then(list => callback(null, {
2016-06-09 15:00:44 +08:00
...nextProps,
2016-08-04 10:52:09 +08:00
localizedPageData: list[0],
demos: list[1],
2016-06-09 15:00:44 +08:00
}));
}
export default (props) => {
2016-07-26 15:24:48 +08:00
return <MainContent {...props} />;
};