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

37 lines
1.0 KiB
React
Raw Normal View History

import React from 'react';
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
2016-06-09 15:00:44 +08:00
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);
}
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 demos = nextProps.utils.get(nextProps.data, [...pageDataPath, '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} />;
};