Use a global config for some parameters
This can later be loaded from JSON or something, but for now it just lives with the rest of the code. I'm already going to mix data with code in this repo and these values shouldn't change much, so I'm fine with that. This is my personal site after all. I'm not expecting to release this in a way for others to use.
This commit is contained in:
parent
6109bb690d
commit
4fce19a7bf
4 changed files with 26 additions and 26 deletions
10
src/App.js
10
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 (
|
||||
<Router>
|
||||
<ScrollToTop>
|
||||
<div className="App">
|
||||
<Header title={this.title} />
|
||||
<Header title={config.title} />
|
||||
|
||||
<Container>
|
||||
<Row>
|
||||
|
|
@ -68,7 +64,7 @@ class App extends Component {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
document.title = this.title;
|
||||
document.title = config.title;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
});
|
||||
|
|
|
|||
19
src/Post.js
19
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);
|
||||
|
||||
|
|
|
|||
15
src/config.js
Normal file
15
src/config.js
Normal file
|
|
@ -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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue