|
@@ -4,9 +4,6 @@ import ReactMarkdown from 'react-markdown';
|
|
|
import { Switch, Route, HashRouter, Link } from 'react-router-dom';
|
|
import { Switch, Route, HashRouter, Link } from 'react-router-dom';
|
|
|
const markdown = require('./markdown.json');
|
|
const markdown = require('./markdown.json');
|
|
|
|
|
|
|
|
-console.log(markdown);
|
|
|
|
|
-const input = '# This is a header\n\nAnd this is a paragraph'
|
|
|
|
|
-
|
|
|
|
|
class Page extends React.Component {
|
|
class Page extends React.Component {
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
Prism.highlightAll();
|
|
Prism.highlightAll();
|
|
@@ -26,34 +23,73 @@ class App extends React.Component {
|
|
|
render() {
|
|
render() {
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
- <Page title={markdown.part1[0].title} md={markdown.part1[0].content} />
|
|
|
|
|
|
|
+ <Page title={markdown[0].items[0].title} md={markdown[0].items[0].content} />
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
class MarkdownPage extends React.Component {
|
|
class MarkdownPage extends React.Component {
|
|
|
render() {
|
|
render() {
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
- <Page title={markdown.part1[1].title} md={markdown.part1[1].content} />
|
|
|
|
|
|
|
+ <Page title={markdown[0].items[1].title} md={markdown[0].items[1].content} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class Section extends React.Component {
|
|
|
|
|
+ render() {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h1>{this.props.title}</h1>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function getSection(sectionIndex) {
|
|
|
|
|
+ const section = markdown[sectionIndex];
|
|
|
|
|
+ return () => (
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h1>{section.title}</h1>
|
|
|
|
|
+ {getSectionLinks(section)}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getSectionLinks(section) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <ul>
|
|
|
|
|
+ {section.items.map((page, pIndex) => (
|
|
|
|
|
+ <li key={pIndex}><Link to={section.path + page.path}>{page.title}</Link></li>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </ul>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
ReactDOM.render(
|
|
ReactDOM.render(
|
|
|
<HashRouter>
|
|
<HashRouter>
|
|
|
<div>
|
|
<div>
|
|
|
- <ul>
|
|
|
|
|
|
|
+ <ul>{
|
|
|
|
|
+ markdown.map((section, sIndex) => (
|
|
|
|
|
+ <li key={sIndex}><Link to={section.path}>{section.title}</Link>
|
|
|
|
|
+ {getSectionLinks(section)}
|
|
|
|
|
+ </li>
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
<li><Link to="/">Home</Link></li>
|
|
<li><Link to="/">Home</Link></li>
|
|
|
- <li><Link to="/md">Md</Link></li>
|
|
|
|
|
</ul>
|
|
</ul>
|
|
|
<Switch>
|
|
<Switch>
|
|
|
<Route exact path="/" component={App} />
|
|
<Route exact path="/" component={App} />
|
|
|
<Route path="/md" component={MarkdownPage} />
|
|
<Route path="/md" component={MarkdownPage} />
|
|
|
|
|
+ {
|
|
|
|
|
+ markdown.map((section, sIndex) => (
|
|
|
|
|
+ <Route key={sIndex} exact path={section.path} component={getSection(sIndex)} />
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
</Switch>
|
|
</Switch>
|
|
|
</div>
|
|
</div>
|
|
|
</HashRouter>,
|
|
</HashRouter>,
|