Add links to pages in the sidebar nav
This commit is contained in:
parent
67dd5dbe17
commit
062185020b
1 changed files with 33 additions and 4 deletions
37
src/Nav.js
37
src/Nav.js
|
|
@ -1,5 +1,6 @@
|
|||
import React, { Component } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import slugify from 'slugify';
|
||||
|
||||
import Icon from 'react-fontawesome';
|
||||
|
||||
|
|
@ -33,15 +34,43 @@ class RouterListLink extends Component {
|
|||
}
|
||||
|
||||
class NavList extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
pageLinks: null,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
fetch('/site.json')
|
||||
.then(resp => resp.json())
|
||||
.then(blob => {
|
||||
let links = [];
|
||||
for (let page of blob.pages) {
|
||||
let slug = page.slug;
|
||||
if (!slug) {
|
||||
slug = slugify(page.title).toLowerCase();
|
||||
}
|
||||
|
||||
if (page.parent == null) {
|
||||
let href = "/" + slug;
|
||||
links.push(<RouterListLink
|
||||
name={page.title}
|
||||
href={href}
|
||||
key={slug}
|
||||
/>);
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({pageLinks: links});
|
||||
});
|
||||
}
|
||||
render() {
|
||||
// TODO: populate these dynamically based on root page names
|
||||
// but keep Home first and RSS at the end
|
||||
return (
|
||||
<Row>
|
||||
<ul>
|
||||
<RouterListLink name="Home" href="/" />
|
||||
<RouterListLink name="About" href="/about" />
|
||||
<RouterListLink name="Projects" href="/projects" />
|
||||
{ this.state.pageLinks }
|
||||
<ListLink name="RSS" href="/rss.xml" icon="rss-square" />
|
||||
</ul>
|
||||
</Row>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue