diff --git a/package.json b/package.json index b87e0e3c39..a2f03696a8 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "babel-eslint": "^6.0.2", "babel-jest": "^12.0.2", "babel-plugin-antd": "^0.4.0", - "bisheng": "^0.2.0", + "bisheng": "^0.3.0", "dom-scroll-into-view": "^1.1.0", "enquire.js": "^2.1.1", "es6-shim": "^0.35.0", diff --git a/site/theme/index.js b/site/theme/index.js index 1c924b6018..d4514c7729 100644 --- a/site/theme/index.js +++ b/site/theme/index.js @@ -12,9 +12,6 @@ export default { Navigation: 3, Other: 4, }, - redirects: { - CHANGELOG: 'docs/react/changelog', - }, docVersions: { '0.9.x': 'http://09x.ant.design/', '0.10.x': 'http://010x.ant.design/', @@ -23,5 +20,9 @@ export default { }, routes: { '/': './template/Home/index', + '/docs/resource/:children': './template/Content/index', + }, + redirects: { + '/docs/resource': '/docs/resource/download', }, }; diff --git a/site/common/styles/page-nav.less b/site/theme/static/page-nav.less similarity index 100% rename from site/common/styles/page-nav.less rename to site/theme/static/page-nav.less diff --git a/site/theme/static/style.js b/site/theme/static/style.js index 147ab7bf1c..724f447e71 100644 --- a/site/theme/static/style.js +++ b/site/theme/static/style.js @@ -2,5 +2,5 @@ import './common.less'; import './header.less'; import './footer.less'; import './home.less'; - +import './page-nav.less'; import './not-found.less'; diff --git a/site/component/MainContent/index.jsx b/site/theme/template/Content/MainContent.jsx similarity index 89% rename from site/component/MainContent/index.jsx rename to site/theme/template/Content/MainContent.jsx index ac1a81b823..bc71be2d30 100644 --- a/site/component/MainContent/index.jsx +++ b/site/theme/template/Content/MainContent.jsx @@ -2,10 +2,15 @@ import React from 'react'; import { Link } from 'react-router'; import scrollIntoView from 'dom-scroll-into-view'; import { Row, Col, Menu } from 'antd'; -import config from '../../website.config'; +import * as utils from '../utils'; +import config from '../../'; const SubMenu = Menu.SubMenu; export default class MainContent extends React.Component { + static contextTypes = { + intl: React.PropTypes.object.isRequired, + } + componentDidMount() { this.scrollToAnchor(this.props); } @@ -39,20 +44,20 @@ export default class MainContent extends React.Component { return props.params.children; } - fileNameToPath(fileName) { - const snippets = fileName.replace(/(\/index)?((\.zh-CN)|(\.en-US))?\.md$/i, '').split('/'); + fileNameToPath(filename) { + const snippets = filename.replace(/(\/index)?((\.zh-CN)|(\.en-US))?\.md$/i, '').split('/'); return snippets[snippets.length - 1]; } generateMenuItem(isTop, item) { - const key = this.fileNameToPath(item.fileName); + const key = this.fileNameToPath(item.filename); const text = isTop ? item.title || item.chinese || item.english : [ {item.title || item.english}, {item.subtitle || item.chinese}, ]; const disabled = item.disabled; - const url = item.fileName.replace(/(\/index)?((\.zh-CN)|(\.en-US))?\.md$/i, ''); + const url = item.filename.replace(/(\/index)?((\.zh-CN)|(\.en-US))?\.md$/i, ''); const child = !item.link ? {text} @@ -95,7 +100,8 @@ export default class MainContent extends React.Component { getMenuItems() { const props = this.props; - const menuItems = props.menuItems; + // TODO: data + const menuItems = utils.getMenuItems(props.data.docs.resource, this.context.intl.locale); const topLevel = this.generateSubMenuItems(menuItems.topLevel); const subMenu = Object.keys(menuItems).filter(this.isNotTopLevel) .sort((a, b) => { @@ -149,7 +155,7 @@ export default class MainContent extends React.Component { {menuItems} diff --git a/site/theme/template/Content/index.jsx b/site/theme/template/Content/index.jsx new file mode 100644 index 0000000000..b0b06dc5f1 --- /dev/null +++ b/site/theme/template/Content/index.jsx @@ -0,0 +1,11 @@ +import React from 'react'; +import Layout from '../Layout'; +import MainContent from './MainContent'; + +export default (props) => { + return ( + + + + ); +}; diff --git a/site/theme/template/Layout/Header.jsx b/site/theme/template/Layout/Header.jsx index ba199c9b18..438239a63c 100644 --- a/site/theme/template/Layout/Header.jsx +++ b/site/theme/template/Layout/Header.jsx @@ -88,10 +88,17 @@ export default class Header extends React.Component { let activeMenuItem = (routes[1] && routes[1].path) || 'home'; activeMenuItem = activeMenuItem === 'components' ? 'docs/react' : activeMenuItem; - const componentsList = Object.keys(data.components) - .map((component) => data.components[component].index) - .filter(item => item); const locale = this.context.intl.locale; + const componentsList = Object.keys(data.components) + .map((component) => { + const index = data.components[component].index; + if (index.meta) { + return index; + } + return index[locale]; + }) + .filter(item => item); + const options = Object.keys(componentsList) .map((key) => { const value = componentsList[key]; diff --git a/site/theme/template/utils.jsx b/site/theme/template/utils.jsx new file mode 100644 index 0000000000..9c8df48c5f --- /dev/null +++ b/site/theme/template/utils.jsx @@ -0,0 +1,29 @@ +export function getMenuItems(data, locale) { + const menuMeta = Object.keys(data) + .map((key) => data[key]) + .map((file) => { + if (file.meta) { + return file.meta; + } + return file[locale].meta; + }); + + const menuItems = {}; + menuMeta.sort((a, b) => { + return parseInt(a.order, 10) - parseInt(b.order, 10); + }).forEach((meta) => { + const category = meta.category || 'topLevel'; + if (!menuItems[category]) { + menuItems[category] = {}; + } + + const type = meta.type || 'topLevel'; + if (!menuItems[category][type]) { + menuItems[category][type] = []; + } + + menuItems[category][type].push(meta); + }); + + return menuItems; +}