mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
import collect from 'bisheng/collect';
|
|
import MainContent from './MainContent';
|
|
import * as utils from '../utils';
|
|
|
|
function isChangelog(pathname) {
|
|
return pathname.indexOf('changelog') >= 0;
|
|
}
|
|
|
|
export default collect(async (nextProps) => {
|
|
const { pathname } = nextProps.location;
|
|
const pageDataPath = pathname.replace('-cn', '').split('/');
|
|
const pageData = isChangelog(pathname) ?
|
|
nextProps.data.changelog.CHANGELOG :
|
|
nextProps.utils.get(nextProps.data, pageDataPath);
|
|
if (!pageData) {
|
|
throw 404; // eslint-disable-line no-throw-literal
|
|
}
|
|
|
|
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);
|