diff --git a/site/entry/index.jsx b/site/entry/index.jsx index f9ad1a0aa5..5d0ac37750 100644 --- a/site/entry/index.jsx +++ b/site/entry/index.jsx @@ -20,22 +20,12 @@ window['react-dom'] = ReactDOM; window.antd = antd; const ReactComponents = utils.generateContainer(reactComponents); -const reactComponentsChildren = utils.generateChildren(reactComponents); - const Practice = utils.generateContainer(practice); -const practiceChildren = utils.generateChildren(practice); - const Pattern = utils.generateContainer(pattern); -const patternChildren = utils.generateChildren(pattern); - const Spec = utils.generateContainer(spec); -const specChildren = utils.generateChildren(spec); - const Resource = utils.generateContainer(resource); -const resourceChildren = utils.generateChildren(resource); - -const redirects = Object.keys(config.redirects).map((from) => { - return ; +const redirects = Object.keys(config.redirects).map((from, index) => { + return ; }); ReactDOM.render( @@ -43,20 +33,30 @@ ReactDOM.render( - { reactComponentsChildren } + { utils.generateIndex(reactComponents) } + { redirects } - { practiceChildren } + { utils.generateIndex(practice) } + - { patternChildren } + { utils.generateIndex(pattern) } + - { specChildren } + { utils.generateIndex(spec) } + - { resourceChildren } + { utils.generateIndex(resource) } + diff --git a/site/entry/utils.js b/site/entry/utils.js index 0325d1c25a..02226bc9e9 100644 --- a/site/entry/utils.js +++ b/site/entry/utils.js @@ -1,9 +1,10 @@ import React from 'react'; -import { Route, IndexRedirect } from 'react-router'; +import { IndexRedirect } from 'react-router'; import MainContent from '../component/MainContent'; import Article from '../component/Article'; import ComponentDoc from '../component/ComponentDoc'; import demosList from '../../_site/data/demos-list'; +import { redirects } from '../website.config'; function fileNameToPath(fileName) { const snippets = fileName.replace(/(\/index)?\.md$/i, '').split('/'); @@ -44,33 +45,29 @@ export function generateContainer(data) { }; } -function getPagesData(data) { - return Object.keys(data) - .map((key) => data[key]); -} - -export function generateChildren(data) { - const pagesData = getPagesData(data); - const children = pagesData.map((pageData, index) => { - const meta = pageData.meta; - const hasDemos = demosList[meta.fileName]; - const Wrapper = !hasDemos ? - (props) =>
: - (props) => ; - return ( - - ); - }); - +export function generateIndex(data) { const menuItems = getMenuItems(data); const firstChild = menuItems.topLevel.topLevel.find((item) => { return item.disabled !== 'true'; }); - children.unshift( + return ( ); - return children; +} + +const pathToFile = {}; +Object.keys(redirects).forEach((key) => pathToFile[redirects[key]] = key); +pathToFile['components/changelog'] = './CHANGELOG'; // TODO +export function getChildrenWrapper(data) { + return function childrenWrapper(props) { + const trimedPathname = props.location.pathname.replace(/^\//, ''); + const processedPathname = pathToFile[trimedPathname] || trimedPathname; + const doc = data[`${processedPathname}.md`] || + data[`${processedPathname}/index.md`]; + const hasDemos = demosList[doc.meta.fileName]; + return !hasDemos ? +
: + ; + }; }