You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
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);
|
|
|