import React from 'react';
import ReactDOM from 'react-dom';
import ReactMarkdown from 'react-markdown';
import { Switch, Route, HashRouter, Link } from 'react-router-dom';
import About from './components/About';
import Home from './components/Home';
import Navbar from './components/Navbar';
import Page from './components/Page';
const markdown = require('./resources/markdown.json');
const $leftPanel = $('#left-panel');
const $window = $(window);
function onResize() {
$leftPanel.css('max-height', $window.height());
}
$window.on('resize', onResize);
function getSection(sectionIndex) {
const section = markdown[sectionIndex];
return () => (
home
{section.title}
{section.title}
{getSectionPageLinks(section)}
);
}
function getSectionPagination(section, activeIndex) {
const lastIndex = section.items.length - 1;
const previousHref = activeIndex === 0 ? section.path :
section.path + section.items[activeIndex - 1].path;
const nextHref = activeIndex === lastIndex ? section.path :
section.path + section.items[activeIndex + 1].path;
return (
-
chevron_left
{
section.items.map((page, pIndex) => (
-
{pIndex + 1}
))
}
-
chevron_right
);
}
function getPage(sectionIndex, pageIndex) {
const section = markdown[sectionIndex];
const page = section.items[pageIndex];
return () => (
{getSectionPagination(section, pageIndex)}
);
}
function getSectionPageLinks(section) {
return (
{section.items.map((page, pIndex) => (
- {page.title}
))}
);
}
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 => );
}
ReactDOM.render(
{
markdown.map(getSectionRoutes)
}
,
document.getElementById('left-panel')
);