ant-design/site/theme/template/Content/index.jsx
lijianan 3d33c34010
chore: use includes instead indexOf (#38139)
* chore: use includes instead indexOf

* fix: fix
2022-10-21 11:45:55 +08:00

31 lines
1.1 KiB
JavaScript

import collect from 'bisheng/collect';
import MainContent from './MainContent';
import * as utils from '../utils';
function isChangelog(pathname) {
return pathname.includes('changelog');
}
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);