2016-02-29 14:08:40 +08:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2016-03-11 09:42:04 +08:00
|
|
|
import { Router, Route, IndexRoute, Redirect, hashHistory } from 'react-router';
|
2016-04-27 20:44:36 +08:00
|
|
|
import antd from '../../index.js';
|
2016-03-02 11:57:37 +08:00
|
|
|
import * as utils from './utils';
|
2016-02-29 14:08:40 +08:00
|
|
|
import '../common/lib';
|
|
|
|
import App from '../component/App';
|
|
|
|
import Home from '../component/Home';
|
2016-04-27 10:56:17 +08:00
|
|
|
import NotFound from '../component/NotFound';
|
2016-03-22 11:32:49 +08:00
|
|
|
import practice from '../../_data/practice';
|
|
|
|
import pattern from '../../_data/pattern';
|
|
|
|
import reactComponents from '../../_data/react-components';
|
|
|
|
import spec from '../../_data/spec';
|
|
|
|
import resource from '../../_data/resource';
|
2016-03-11 14:12:05 +08:00
|
|
|
import config from '../website.config';
|
2016-02-29 14:08:40 +08:00
|
|
|
|
2016-03-08 16:12:04 +08:00
|
|
|
// TODO: pack dependencies with atool build
|
2016-03-08 15:13:59 +08:00
|
|
|
// Expose React, ReactDOM
|
|
|
|
window.react = React;
|
|
|
|
window['react-dom'] = ReactDOM;
|
|
|
|
window.antd = antd;
|
|
|
|
|
2016-03-11 09:42:04 +08:00
|
|
|
const ReactComponents = utils.generateContainer(reactComponents);
|
|
|
|
const Practice = utils.generateContainer(practice);
|
|
|
|
const Pattern = utils.generateContainer(pattern);
|
|
|
|
const Spec = utils.generateContainer(spec);
|
|
|
|
const Resource = utils.generateContainer(resource);
|
2016-03-21 10:33:27 +08:00
|
|
|
const redirects = Object.keys(config.redirects).map((from, index) => {
|
2016-03-21 10:44:31 +08:00
|
|
|
return <Redirect from={from} to={config.redirects[from]} key={index} />;
|
2016-03-11 14:12:05 +08:00
|
|
|
});
|
|
|
|
|
2016-03-25 17:35:26 +08:00
|
|
|
// Enable Google Analytics
|
|
|
|
if (!location.port) {
|
|
|
|
/* eslint-disable */
|
|
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
|
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
|
|
ga('create', 'UA-72788897-1', 'auto');
|
|
|
|
ga('send', 'pageview');
|
|
|
|
|
|
|
|
hashHistory.listen((loc) => {
|
|
|
|
ga('send', 'pageview', loc.pathname + loc.search);
|
|
|
|
});
|
|
|
|
/* eslint-enable */
|
|
|
|
}
|
|
|
|
|
2016-03-03 11:12:46 +08:00
|
|
|
ReactDOM.render(
|
|
|
|
<Router history={hashHistory}>
|
|
|
|
<Route path="/" component={App}>
|
|
|
|
<IndexRoute component={Home} />
|
|
|
|
<Route path="components" component={ReactComponents}>
|
2016-03-21 10:33:27 +08:00
|
|
|
{ utils.generateIndex(reactComponents) }
|
|
|
|
<Route path=":children"
|
|
|
|
component={utils.getChildrenWrapper(reactComponents)} />
|
2016-03-03 11:12:46 +08:00
|
|
|
</Route>
|
2016-03-11 14:12:05 +08:00
|
|
|
{ redirects }
|
2016-03-10 16:56:17 +08:00
|
|
|
<Route path="docs/practice" component={Practice}>
|
2016-03-21 10:33:27 +08:00
|
|
|
{ utils.generateIndex(practice) }
|
|
|
|
<Route path=":children"
|
|
|
|
component={utils.getChildrenWrapper(practice)} />
|
2016-03-03 11:12:46 +08:00
|
|
|
</Route>
|
2016-03-10 16:56:17 +08:00
|
|
|
<Route path="docs/pattern" component={Pattern}>
|
2016-03-21 10:33:27 +08:00
|
|
|
{ utils.generateIndex(pattern) }
|
|
|
|
<Route path=":children"
|
|
|
|
component={utils.getChildrenWrapper(pattern)} />
|
2016-03-03 11:12:46 +08:00
|
|
|
</Route>
|
2016-03-10 16:56:17 +08:00
|
|
|
<Route path="docs/spec" component={Spec}>
|
2016-03-21 10:33:27 +08:00
|
|
|
{ utils.generateIndex(spec) }
|
|
|
|
<Route path=":children"
|
|
|
|
component={utils.getChildrenWrapper(spec)} />
|
2016-03-03 11:12:46 +08:00
|
|
|
</Route>
|
2016-03-10 16:56:17 +08:00
|
|
|
<Route path="docs/resource" component={Resource}>
|
2016-03-21 10:33:27 +08:00
|
|
|
{ utils.generateIndex(resource) }
|
|
|
|
<Route path=":children"
|
|
|
|
component={utils.getChildrenWrapper(resource)} />
|
2016-03-03 11:12:46 +08:00
|
|
|
</Route>
|
2016-02-29 14:08:40 +08:00
|
|
|
</Route>
|
2016-04-27 10:56:17 +08:00
|
|
|
<Route path="*" component={NotFound} />
|
2016-03-03 11:12:46 +08:00
|
|
|
</Router>
|
|
|
|
, document.getElementById('react-content')
|
|
|
|
);
|