diff --git a/src/App.js b/src/App.js index 77e6002..19edb64 100644 --- a/src/App.js +++ b/src/App.js @@ -10,6 +10,7 @@ import 'highlight.js/styles/github-gist.css'; import { Container, Row, Column } from './skeleton'; +import config from './config'; import { Footer } from './Footer'; import { Header } from './Header'; import { NavList, TagNav } from './Nav'; @@ -19,17 +20,12 @@ import { Page } from './Page'; class App extends Component { - constructor(props) { - super(props); - this.title = 'Nick Pegg'; - } - render() { return (
-
+
@@ -68,7 +64,7 @@ class App extends Component { } componentDidMount() { - document.title = this.title; + document.title = config.title; } } diff --git a/src/Nav.js b/src/Nav.js index 6f2377e..c1bd57c 100644 --- a/src/Nav.js +++ b/src/Nav.js @@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'; import Icon from 'react-fontawesome'; +import config from './config'; import { Row } from './skeleton'; import { slugify } from './util'; @@ -68,11 +69,6 @@ class NavList extends Component { class TagNav extends Component { constructor (props) { super(props); - - // TODO: fetch this number from config - // Number of top tags to display - this.numTop = 5; - this.state = { topTags: [], } @@ -118,7 +114,7 @@ class TagNav extends Component { tags = tags.map(t => t[0]); // Get top N - tags = tags.slice(0, this.numTop); + tags = tags.slice(0, config.numTopTags); this.setState({topTags: tags}); }); diff --git a/src/Post.js b/src/Post.js index 92b515c..b3682a6 100644 --- a/src/Post.js +++ b/src/Post.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; +import config from './config'; import { Article } from './Article'; import { HistoryNav } from './Nav'; import { NotFound } from './NotFound'; @@ -44,11 +45,7 @@ class Post extends Component { } } - if (!found) { - console.log('post not found'); - /* TODO: return 404 */ - this.setState({notFound: true}); - } + this.setState({notFound: !found}); }); } @@ -84,10 +81,6 @@ class Posts extends Component { constructor(props) { super(props); - // Number of Articles per page - // TODO: Pull this from a configuration somehow - this.perPage = 5; - this.params = props.match.params; this.state = { posts: null, @@ -112,7 +105,7 @@ class Posts extends Component { if (!page) { page = 0; } - offset = page * this.perPage; + offset = page * config.numPostsPerPage; // if tag is set, filter posts down to that of that tag if (this.params.tag) { @@ -120,12 +113,12 @@ class Posts extends Component { } // Grab the slice of posts for this page - let post_slice = posts.slice(offset, offset + this.perPage); + let post_slice = posts.slice(offset, offset + config.numPostsPerPage); // Check to see if we have more posts after these - let nextOffset = (page + 1) * this.perPage; + let nextOffset = (page + 1) * config.numPostsPerPage; let nextPosts = posts.slice(nextOffset, - nextOffset + this.perPage); + nextOffset + config.numPostsPerPage); let hasMore = nextPosts.length > 0; this.updateHistoryNav(page, hasMore); diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..3900faf --- /dev/null +++ b/src/config.js @@ -0,0 +1,15 @@ +// App-wide config parameters +// This should probably load from JSON at some point, but code and data are +// living together for now, so this can be split out at that time. + + +const config = { + title: 'Nick Pegg', + + numPostsPerPage: 5, + + // Number of top tags to display in the sidebar nav + numTopTags: 5, +}; + +export default config;