mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-29 03:48:26 +08:00
36 lines
1004 B
JavaScript
36 lines
1004 B
JavaScript
import React from 'react';
|
|
import MainContent from './MainContent';
|
|
import Promise from 'bluebird';
|
|
|
|
// locale copy from layout
|
|
const locale = (
|
|
window.localStorage &&
|
|
localStorage.getItem('locale') !== 'en-US'
|
|
) ? 'zh-CN' : 'en-US';
|
|
|
|
export function collect(nextProps, callback) {
|
|
const pageData = nextProps.location.pathname === 'changelog' ?
|
|
nextProps.data.CHANGELOG : nextProps.pageData;
|
|
const pageDataPromise = typeof pageData === 'function' ?
|
|
pageData() : (pageData[locale] || pageData.index[locale] || pageData.index)();
|
|
const promises = [pageDataPromise];
|
|
|
|
const pathname = nextProps.location.pathname;
|
|
const demos = nextProps.utils.get(
|
|
nextProps.data, [...pathname.split('/'), 'demo']
|
|
);
|
|
if (demos) {
|
|
promises.push(demos());
|
|
}
|
|
Promise.all(promises)
|
|
.then((list) => callback(null, {
|
|
...nextProps,
|
|
localizedPageData: list[0],
|
|
demos: list[1],
|
|
}));
|
|
}
|
|
|
|
export default (props) => {
|
|
return <MainContent {...props} />;
|
|
};
|