refactor: fixes linting errors pages/index.jsx

This commit is contained in:
Simon Reinsperger 2017-03-08 17:16:26 +01:00
parent a1cee07124
commit db448ba9d1

View File

@ -1,61 +1,58 @@
import React from 'react' import React from 'react';
import { Link } from 'react-router' import { Link } from 'react-router';
import sortBy from 'lodash/sortBy' import sortBy from 'lodash/sortBy';
import moment from 'moment' import moment from 'moment';
import Helmet from 'react-helmet' import Helmet from 'react-helmet';
import { prefixLink } from 'gatsby-helpers' import { prefixLink } from 'gatsby-helpers';
import access from 'safe-access' import access from 'safe-access';
import { config } from 'config' import { config } from 'config';
import SitePost from '../components/SitePost' import SiteSidebar from '../components/SiteSidebar';
import SiteSidebar from '../components/SiteSidebar'
class SiteIndex extends React.Component { class SiteIndex extends React.Component {
render() { render() {
const pageLinks = [] const pageLinks = [];
// Sort pages. // Sort pages.
const sortedPages = sortBy(this.props.route.pages, (page) => access(page, 'data.date') const sortedPages = sortBy(this.props.route.pages, page => access(page, 'data.date')).reverse();
).reverse()
sortedPages.forEach((page) => { sortedPages.forEach((page) => {
if (access(page, 'file.ext') === 'md' && access(page, 'data.layout') === 'post') { if (access(page, 'file.ext') === 'md' && access(page, 'data.layout') === 'post') {
const title = access(page, 'data.title') || page.path const title = access(page, 'data.title') || page.path;
const description = access(page, 'data.description') const description = access(page, 'data.description');
const datePublished = access(page, 'data.date') const datePublished = access(page, 'data.date');
const category = access(page, 'data.category') const category = access(page, 'data.category');
pageLinks.push( pageLinks.push((
<div className='blog-post' key={ title }> <div className="blog-post" key={title}>
<time dateTime={moment(datePublished).format('MMMM D, YYYY')}> <time dateTime={moment(datePublished).format('MMMM D, YYYY')}>
{moment(datePublished).format('MMMM YYYY')} {moment(datePublished).format('MMMM YYYY')}
</time> </time>
<span style={ { padding: '5px'} }></span> <span style={{ padding: '5px' }} />
<span className='blog-category'>{ category }</span> <span className="blog-category">{category}</span>
<h2><Link style={ { borderBottom: 'none',} } to={ prefixLink(page.path) } > { title } </Link></h2> <h2><Link style={{ borderBottom: 'none' }} to={prefixLink(page.path)}>{title}</Link></h2>
<p dangerouslySetInnerHTML={{ __html: description }} /> <p dangerouslySetInnerHTML={{ __html: description }} />
<Link className='readmore' to={ prefixLink(page.path) }> Read <Link className="readmore" to={prefixLink(page.path)}>Read</Link>
</Link>
</div> </div>
) ));
} }
}) });
return ( return (
<div> <div>
<Helmet title={config.siteTitle} /> <Helmet title={config.siteTitle} />
<SiteSidebar {...this.props} /> <SiteSidebar {...this.props} />
<div className='content'> <div className="content">
<div className='main'> <div className="main">
<div className='main-inner'> <div className="main-inner">
{pageLinks} {pageLinks}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
) );
} }
} }
SiteIndex.propTypes = { SiteIndex.propTypes = {
route: React.PropTypes.object, route: React.PropTypes.object,
} };
export default SiteIndex export default SiteIndex;