|
|
@@ -1,9 +1,8 @@
|
|
|
import React from 'react';
|
|
|
-import ReactMarkdown from 'react-markdown';
|
|
|
-import { Switch, Route, HashRouter, Link } from 'react-router-dom';
|
|
|
+import { Switch, HashRouter, Link } from 'react-router-dom';
|
|
|
import About from './components/About';
|
|
|
import Home from './components/Home';
|
|
|
-import Navbar from './components/Navbar';
|
|
|
+import Layout from './components/Layout';
|
|
|
import Page from './components/Page';
|
|
|
const markdown = require('./resources/markdown.json');
|
|
|
|
|
|
@@ -14,9 +13,11 @@ const markdown = require('./resources/markdown.json');
|
|
|
// }
|
|
|
// $window.on('resize', onResize);
|
|
|
|
|
|
-function getSection(sectionIndex) {
|
|
|
- const section = markdown[sectionIndex];
|
|
|
- return () => (
|
|
|
+function Section({ match }) {
|
|
|
+ const { params: { sectionSlug } } = match;
|
|
|
+ const sectionPath = `/${sectionSlug}`;
|
|
|
+ const section = markdown.find(s => s.path === sectionPath);
|
|
|
+ return (
|
|
|
<div>
|
|
|
<div className="breadcrumb-wrapper">
|
|
|
<Link to='/' className="breadcrumb light-blue-text"><i className="material-icons">home</i></Link>
|
|
|
@@ -55,10 +56,14 @@ function getSectionPagination(section, activeIndex) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-function getPage(sectionIndex, pageIndex) {
|
|
|
- const section = markdown[sectionIndex];
|
|
|
+function PageWrap({ match }) {
|
|
|
+ const { params: { sectionSlug, pageSlug } } = match;
|
|
|
+ const sectionPath = `/${sectionSlug}`;
|
|
|
+ const section = markdown.find(s => s.path === sectionPath);
|
|
|
+ const pagePath = `/${pageSlug}`;
|
|
|
+ const pageIndex = section.items.findIndex(p => p.path === pagePath);
|
|
|
const page = section.items[pageIndex];
|
|
|
- return () => (
|
|
|
+ return (
|
|
|
<div>
|
|
|
<Page page={page} section={section} />
|
|
|
{getSectionPagination(section, pageIndex)}
|
|
|
@@ -77,31 +82,27 @@ function getSectionPageLinks(section) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-function getSectionRoutes(section, sIndex) {
|
|
|
- const routes = [{
|
|
|
- key: sIndex, path: section.path, component: getSection(sIndex)
|
|
|
- }].concat(section.items.map((page, pIndex) => ({
|
|
|
- key: sIndex + '-' + pIndex,
|
|
|
- path: section.path + page.path,
|
|
|
- component: getPage(sIndex, pIndex)
|
|
|
- })));
|
|
|
- return routes.map(r => <Route key={r.key} exact path={r.path} component={r.component} />);
|
|
|
-}
|
|
|
+// function getSectionRoutes(section, sIndex) {
|
|
|
+// const routes = [
|
|
|
+// // {
|
|
|
+// // key: sIndex, path: section.path, component: getSection(sIndex)
|
|
|
+// // }
|
|
|
+// ].concat(section.items.map((page, pIndex) => ({
|
|
|
+// key: sIndex + '-' + pIndex,
|
|
|
+// path: section.path + page.path,
|
|
|
+// component: getPage(sIndex, pIndex)
|
|
|
+// })));
|
|
|
+// return routes.map(r => <Layout key={r.key} exact path={r.path} component={r.component} />);
|
|
|
+// }
|
|
|
|
|
|
const App = () => (
|
|
|
- <HashRouter>
|
|
|
- <div id="react-wrapper">
|
|
|
- <Navbar />
|
|
|
- <div className="main">
|
|
|
- <Switch>
|
|
|
- <Route exact path="/" component={Home} />
|
|
|
- <Route exact path="/a-propos" component={About} />
|
|
|
- {
|
|
|
- markdown.map(getSectionRoutes)
|
|
|
- }
|
|
|
- </Switch>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ <HashRouter>
|
|
|
+ <Switch>
|
|
|
+ <Layout path="/:sectionSlug/:pageSlug" component={PageWrap} />
|
|
|
+ <Layout path="/:sectionSlug" component={Section} />
|
|
|
+ <Layout exact path="/a-propos" component={About} />
|
|
|
+ <Layout exact path="/" component={Home} />
|
|
|
+ </Switch>
|
|
|
</HashRouter>
|
|
|
);
|
|
|
|