rickvanlieshout.com/pages/index.jsx

62 lines
2.3 KiB
React
Raw Normal View History

2016-03-11 23:28:19 +01:00
import React from 'react'
import { Link } from 'react-router'
import sortBy from 'lodash/sortBy'
2016-06-03 01:32:38 +02:00
import moment from 'moment'
2016-03-11 23:28:19 +01:00
import DocumentTitle from 'react-document-title'
2016-06-03 01:32:38 +02:00
import { prefixLink } from 'gatsby-helpers'
2016-03-11 23:28:19 +01:00
import access from 'safe-access'
import { config } from 'config'
2016-06-03 13:05:50 +02:00
import SitePost from '../components/SitePost'
import SiteSidebar from '../components/SiteSidebar'
2016-06-03 01:32:38 +02:00
2016-06-03 13:05:50 +02:00
class SiteIndex extends React.Component {
2016-03-21 18:03:01 +01:00
render() {
const pageLinks = []
// Sort pages.
const sortedPages = sortBy(this.props.route.pages, (page) => access(page, 'data.date')
).reverse()
sortedPages.forEach((page) => {
if (access(page, 'file.ext') === 'md' && access(page, 'data.layout') === 'post') {
const title = access(page, 'data.title') || page.path
const description = access(page, 'data.description')
const datePublished = access(page, 'data.date')
const category = access(page, 'data.category')
2016-03-11 23:28:19 +01:00
2016-03-21 18:03:01 +01:00
pageLinks.push(
<div className='blog-post'>
<time dateTime={ moment(datePublished).format('MMMM D, YYYY') }>
{ moment(datePublished).format('MMMM YYYY') }
</time>
<span style={ { padding: '5px'} }></span>
<span className='blog-category'>{ category }</span>
2016-06-03 01:32:38 +02:00
<h2><Link style={ { borderBottom: 'none',} } to={ prefixLink(page.path) } > { title } </Link></h2>
2016-03-21 18:03:01 +01:00
<p dangerouslySetInnerHTML={ { __html: description} } />
2016-06-03 01:32:38 +02:00
<Link className='readmore' to={ prefixLink(page.path) }> Read
2016-03-21 18:03:01 +01:00
</Link>
</div>
)
}
})
2016-03-11 23:28:19 +01:00
2016-03-21 18:03:01 +01:00
return (
<DocumentTitle title={ config.siteTitle }>
<div>
2016-06-03 13:05:50 +02:00
<SiteSidebar {...this.props}/>
2016-03-21 18:03:01 +01:00
<div className='content'>
<div className='main'>
<div className='main-inner'>
{ pageLinks }
</div>
</div>
</div>
2016-03-11 23:28:19 +01:00
</div>
2016-03-21 18:03:01 +01:00
</DocumentTitle>
)
}
2016-03-11 23:28:19 +01:00
}
2016-06-03 13:05:50 +02:00
SiteIndex.propTypes = {
2016-03-21 18:03:01 +01:00
route: React.PropTypes.object,
2016-03-11 23:28:19 +01:00
}
2016-06-03 13:05:50 +02:00
export default SiteIndex