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

31 lines
1.1 KiB
React
Raw Normal View History

2017-02-09 16:55:29 +08:00
import collect from 'bisheng/collect';
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
2017-02-09 16:55:29 +08:00
function isChangelog(pathname) {
return pathname.indexOf('changelog') >= 0;
}
2018-12-07 16:17:45 +08:00
export default collect(async nextProps => {
2017-10-09 13:23:20 +08:00
const { pathname } = nextProps.location;
const pageDataPath = pathname.replace('-cn', '').split('/');
const pageData = isChangelog(pathname)
? nextProps.data.changelog.CHANGELOG
: nextProps.utils.get(nextProps.data, pageDataPath);
2016-09-20 16:48:34 +08:00
if (!pageData) {
2017-02-09 17:42:41 +08:00
throw 404; // eslint-disable-line no-throw-literal
2016-09-20 16:48:34 +08:00
}
2017-02-09 16:55:29 +08:00
const locale = utils.isZhCN(pathname) ? 'zh-CN' : 'en-US';
2018-12-07 16:17:45 +08:00
const pageDataPromise =
typeof pageData === 'function'
? pageData()
: (pageData[locale] || pageData.index[locale] || pageData.index)();
2017-02-09 16:55:29 +08:00
const demosFetcher = nextProps.utils.get(nextProps.data, [...pageDataPath, 'demo']);
if (demosFetcher) {
2017-02-09 17:42:41 +08:00
const [localizedPageData, demos] = await Promise.all([pageDataPromise, demosFetcher()]);
return { localizedPageData, demos };
2016-06-09 15:00:44 +08:00
}
2017-02-09 16:55:29 +08:00
return { localizedPageData: await pageDataPromise };
})(MainContent);