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';
|
2016-10-18 11:18:25 +08:00
|
|
|
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;
|
2016-12-09 13:02:16 +08:00
|
|
|
const pageDataPath = pathname.replace('-cn', '').split('/');
|
2018-06-22 21:05:13 +08:00
|
|
|
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);
|