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

36 lines
1004 B
React
Raw Normal View History

import React from 'react';
import MainContent from './MainContent';
2016-06-09 15:00:44 +08:00
import Promise from 'bluebird';
2016-08-04 10:52:09 +08:00
// locale copy from layout
const locale = (
window.localStorage &&
localStorage.getItem('locale') !== 'en-US'
) ? 'zh-CN' : 'en-US';
2016-06-09 15:00:44 +08:00
export function collect(nextProps, callback) {
2016-08-04 10:52:09 +08:00
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];
2016-06-09 15:00:44 +08:00
const pathname = nextProps.location.pathname;
2016-08-04 10:52:09 +08:00
const demos = nextProps.utils.get(
nextProps.data, [...pathname.split('/'), 'demo']
);
2016-06-09 15:00:44 +08:00
if (demos) {
2016-08-03 14:39:55 +08:00
promises.push(demos());
2016-06-09 15:00:44 +08:00
}
Promise.all(promises)
.then((list) => callback(null, {
...nextProps,
2016-08-04 10:52:09 +08:00
localizedPageData: list[0],
demos: list[1],
2016-06-09 15:00:44 +08:00
}));
}
export default (props) => {
2016-07-26 15:24:48 +08:00
return <MainContent {...props} />;
};