ant-design/site/entry/utils.js

27 lines
737 B
JavaScript
Raw Normal View History

2016-03-02 11:57:37 +08:00
import React from 'react';
import { Route, IndexRedirect } from 'react-router';
import Article from '../component/Article';
2016-03-02 17:12:43 +08:00
function dashed(name) {
return name.toLowerCase().trim().replace(/\s+/g, '-');
}
2016-03-02 11:57:37 +08:00
export function generateChildren(pagesData) {
const children = pagesData.map((pageData, index) => {
const ArticleWrapper = () => <Article content={pageData} />;
return (
<Route key={index}
2016-03-02 17:12:43 +08:00
path={dashed(pageData.meta.english)}
2016-03-02 11:57:37 +08:00
component={ArticleWrapper} />
);
});
const firstChild = pagesData.find((pageData) => {
return pageData.meta.disabled !== 'true';
});
children.unshift(
<IndexRedirect key="index"
2016-03-02 17:12:43 +08:00
to={dashed(firstChild.meta.english)} />
2016-03-02 11:57:37 +08:00
);
return children;
}