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

41 lines
1.2 KiB
React
Raw Normal View History

import React from 'react';
2016-06-09 15:00:44 +08:00
import Promise from 'bluebird';
2016-08-23 21:00:35 +08:00
import MainContent from './MainContent';
2016-08-04 10:52:09 +08:00
// locale copy from layout
2016-09-10 11:19:03 +08:00
const language = (typeof localStorage === 'undefined' || !localStorage.getItem('locale')) ?
navigator.language : localStorage.getItem('locale');
const isZhCN = language === 'zh-CN';
const locale = isZhCN ? '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;
2016-09-20 16:48:34 +08:00
if (!pageData) {
callback(404, nextProps);
return;
}
2016-08-04 10:52:09 +08:00
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, {
2016-06-09 15:00:44 +08:00
...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} />;
};