Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
169 additions
and 80 deletions.
- +1 −0 gatsby-config.js
- +16 −0 gatsby-node.js
- +35 −11 package-lock.json
- +0 −69 src/pages/index.js
- +117 −0 src/templates/blog-list.js
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,117 @@ | ||
import React from 'react' | ||
import { Link, graphql } from 'gatsby' | ||
|
||
import Bio from '../components/Bio' | ||
import Layout from '../components/Layout' | ||
import SEO from '../components/seo' | ||
import { rhythm } from '../utils/typography' | ||
|
||
class BlogIndex extends React.Component { | ||
render() { | ||
const { data } = this.props | ||
const siteTitle = data.site.siteMetadata.title | ||
const siteKeywords = data.site.siteMetadata.keywords | ||
const posts = data.allMarkdownRemark.edges | ||
const { currentPage, numPages } = this.props.pageContext | ||
const isFirst = currentPage === 1 | ||
const isLast = currentPage === numPages | ||
const prevPage = currentPage - 1 === 1 ? '/' : (currentPage - 1).toString() | ||
const nextPage = (currentPage + 1).toString() | ||
|
||
return ( | ||
<Layout location={this.props.location} title={siteTitle}> | ||
<SEO title={siteTitle} keywords={siteKeywords} /> | ||
<Bio /> | ||
{posts.map(({ node }) => { | ||
const title = node.frontmatter.title || node.fields.slug | ||
return ( | ||
<div key={node.fields.slug}> | ||
<h3 | ||
style={{ | ||
marginBottom: rhythm(1 / 4), | ||
}} | ||
> | ||
<Link style={{ boxShadow: `none` }} to={node.fields.slug}> | ||
{title} | ||
</Link> | ||
</h3> | ||
<small>{node.frontmatter.date}</small> | ||
<p dangerouslySetInnerHTML={{ __html: node.excerpt }} /> | ||
</div> | ||
) | ||
})} | ||
<ul | ||
style={{ | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
listStyle: 'none', | ||
padding: 0, | ||
}} | ||
> | ||
{!isFirst && ( | ||
<Link to={prevPage} rel="prev"> | ||
← Previous Page | ||
</Link> | ||
)} | ||
{Array.from({ length: numPages }, (_, i) => ( | ||
<li | ||
key={`pagination-number${i + 1}`} | ||
style={{ | ||
margin: 0, | ||
}} | ||
> | ||
<Link | ||
to={`/${i === 0 ? '' : i + 1}`} | ||
style={{ | ||
padding: rhythm(1 / 4), | ||
textDecoration: 'none', | ||
color: i + 1 === currentPage ? '#ffffff' : '', | ||
background: i + 1 === currentPage ? '#007acc' : '', | ||
}} | ||
> | ||
{i + 1} | ||
</Link> | ||
</li> | ||
))} | ||
{!isLast && ( | ||
<Link to={nextPage} rel="next"> | ||
Next Page → | ||
</Link> | ||
)} | ||
</ul> | ||
</Layout> | ||
) | ||
} | ||
} | ||
|
||
export default BlogIndex | ||
|
||
export const pageQuery = graphql` | ||
query blogPageQuery($skip: Int!, $limit: Int!) { | ||
site { | ||
siteMetadata { | ||
title | ||
} | ||
} | ||
allMarkdownRemark( | ||
sort: { fields: [frontmatter___date], order: DESC } | ||
limit: $limit | ||
skip: $skip | ||
) { | ||
edges { | ||
node { | ||
excerpt | ||
fields { | ||
slug | ||
} | ||
frontmatter { | ||
date(formatString: "MMMM DD, YYYY") | ||
title | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` |