diff --git a/components/anchor/anchorHelper.tsx b/components/anchor/anchorHelper.tsx index ab90da0808..9f4d6f306e 100644 --- a/components/anchor/anchorHelper.tsx +++ b/components/anchor/anchorHelper.tsx @@ -87,6 +87,10 @@ class AnchorHelper { getCurrentAnchor(bounds = 5) { let activeAnchor = ''; + if (typeof document === 'undefined') { + return activeAnchor; + } + this.links.forEach(section => { const target = document.getElementById(section.substring(1)); if (target) { diff --git a/package.json b/package.json index 2a7337b84c..5cc4f6ae27 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,10 @@ "@types/react": "~0.14.41", "@types/react-dom": "~0.14.18", "antd-tools": "0.14.2", + "babel-cli": "^6.18.0", + "babel-preset-es2015": "^6.18.0", + "babel-preset-react": "^6.16.0", + "babel-preset-stage-0": "^6.16.0", "babel-eslint": "^7.1.0", "babel-jest": "^17.0.0", "babel-plugin-import": "^1.0.0", @@ -131,8 +135,15 @@ "typescript-babel-jest": "^0.1.5", "values.js": "^1.0.3" }, + "babel": { + "presets": [ + "es2015", + "react", + "stage-0" + ] + }, "scripts": { - "test": "npm run lint && npm run dist && npm run jest", + "test": "npm run lint && npm run dist && npm run jest && npm run site", "lint": "npm run tslint && npm run eslint && npm run demolint && npm run lesshint", "tslint": "antd-tools run ts-lint && npm run compile && rm -rf lib", "eslint": "eslint test site scripts ./.eslintrc.js ./webpack.config.js --ext '.js,.jsx,.tsx' --ignore-pattern '!.eslintrc.js'", @@ -147,8 +158,10 @@ "compile": "antd-tools run compile && node ./tests/dekko/lib.test.js", "start": "bisheng start -c ./site/bisheng.config.js --no-livereload", - "site": "bisheng build -c ./site/bisheng.config.js", - "deploy": "npm run clean && bisheng gh-pages -c ./site/bisheng.config.js", + "babel-site": "babel ./site/theme/template --out-dir ./site/theme/template", + "clean-site": "rm site/theme/template/**/*.js site/theme/template/*.js", + "site": "npm run babel-site && bisheng build --ssr -c ./site/bisheng.config.js && npm run clean-site", + "deploy": "npm run clean && npm run site && bisheng gh-pages --push-only", "pub": "antd-tools run update-self && antd-tools run pub", "prepublish": "antd-tools run guard", diff --git a/site/theme/en-US.js b/site/theme/en-US.js index 63ef4fe0e2..e8b6a52e03 100644 --- a/site/theme/en-US.js +++ b/site/theme/en-US.js @@ -1,4 +1,4 @@ -import appLocaleData from 'react-intl/locale-data/en'; +const appLocaleData = require('react-intl/locale-data/en'); module.exports = { locale: 'en-US', diff --git a/site/theme/static/common.less b/site/theme/static/common.less index e5016fc877..b6c5c8099a 100644 --- a/site/theme/static/common.less +++ b/site/theme/static/common.less @@ -101,8 +101,11 @@ div.main-container { animation: loadTween 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) infinite; } } -#react-content:empty + .ant-site-loading { - opacity: 1; +#react-content[hidden] { + display: none; + + .ant-site-loading { + opacity: 1; + } } #loading-text { diff --git a/site/theme/static/style.js b/site/theme/static/style.js index d74e52ee9f..344678a141 100644 --- a/site/theme/static/style.js +++ b/site/theme/static/style.js @@ -1 +1,2 @@ +import 'react-github-button/assets/style.css'; import './index.less'; diff --git a/site/theme/static/template.html b/site/theme/static/template.html index b9c57fb49d..d29741fcf9 100644 --- a/site/theme/static/template.html +++ b/site/theme/static/template.html @@ -24,24 +24,28 @@ -
-
- -
One Design Language
-
- - - + + + diff --git a/site/theme/template/Content/MainContent.jsx b/site/theme/template/Content/MainContent.jsx index 3317e1cd17..e5c0570795 100644 --- a/site/theme/template/Content/MainContent.jsx +++ b/site/theme/template/Content/MainContent.jsx @@ -9,7 +9,7 @@ import config from '../../'; const SubMenu = Menu.SubMenu; function getActiveMenuItem(props) { - return props.params.children || props.location.pathname; + return props.params.children || props.location.pathname.replace(/^\//, ''); } function fileNameToPath(filename) { @@ -120,8 +120,8 @@ export default class MainContent extends React.Component { getModuleData(props) { const pathname = props.location.pathname; - const moduleName = /^components/.test(pathname) ? - 'components' : pathname.split('/').slice(0, 2).join('/'); + const moduleName = /^\/?components/.test(pathname) ? + 'components' : pathname.split('/').filter(item => item).slice(0, 2).join('/'); const moduleData = moduleName === 'components' || moduleName === 'changelog' || moduleName === 'docs/react' ? [...props.picked.components, ...props.picked['docs/react'], ...props.picked.changelog] : props.picked[moduleName]; diff --git a/site/theme/template/Content/index.jsx b/site/theme/template/Content/index.jsx index d2a2f9b92b..605f346913 100644 --- a/site/theme/template/Content/index.jsx +++ b/site/theme/template/Content/index.jsx @@ -5,7 +5,7 @@ import * as utils from '../utils'; const locale = utils.isZhCN() ? 'zh-CN' : 'en-US'; export function collect(nextProps, callback) { - const pageData = nextProps.location.pathname === 'changelog' ? + const pageData = nextProps.location.pathname.endsWith('changelog') ? nextProps.data.CHANGELOG : nextProps.pageData; if (!pageData) { callback(404, nextProps); diff --git a/site/theme/template/Home/Banner.jsx b/site/theme/template/Home/Banner.jsx index 9eb5d8ae24..7424805107 100644 --- a/site/theme/template/Home/Banner.jsx +++ b/site/theme/template/Home/Banner.jsx @@ -3,7 +3,6 @@ import { Link } from 'react-router'; import { FormattedMessage } from 'react-intl'; import ScrollElement from 'rc-scroll-anim/lib/ScrollElement'; import GitHubButton from 'react-github-button'; -import 'react-github-button/assets/style.css'; import { Icon } from 'antd'; import QueueAnim from 'rc-queue-anim'; diff --git a/site/theme/template/Home/Page1.jsx b/site/theme/template/Home/Page1.jsx index 86662daf70..58bd02ccd2 100644 --- a/site/theme/template/Home/Page1.jsx +++ b/site/theme/template/Home/Page1.jsx @@ -6,8 +6,8 @@ import ScrollOverPack from 'rc-scroll-anim/lib/ScrollOverPack'; import { Icon, Button } from 'antd'; import QueueAnim from 'rc-queue-anim'; -const clientHeight = document.documentElement.clientHeight; function onScrollEvent(e) { + const clientHeight = document.documentElement.clientHeight; const header = document.getElementById('header'); if (e.pageY >= clientHeight) { if (header.className.indexOf('home-nav-bottom') < 0) { diff --git a/site/theme/template/Layout/Footer.jsx b/site/theme/template/Layout/Footer.jsx index d241ed419e..2645ed5f89 100644 --- a/site/theme/template/Layout/Footer.jsx +++ b/site/theme/template/Layout/Footer.jsx @@ -30,8 +30,10 @@ class Footer extends React.Component { // 大版本发布后全局弹窗提示 // 1. 点击『知道了』之后不再提示 // 2. 超过截止日期后不再提示 - if (localStorage.getItem('antd@2.0.0-notification-sent') !== 'true' && - Date.now() < new Date('2016/10/14').getTime()) { + if ( + localStorage.getItem('antd@2.0.0-notification-sent') !== 'true' && + Date.now() < new Date('2016/10/14').getTime() + ) { this.infoNewVersion(); } } @@ -65,9 +67,8 @@ class Footer extends React.Component { } render() { - const options = Object.keys(docVersions).map(version => ( - - )); + const options = Object.keys(docVersions) + .map(version => ); return (