-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
169 additions
and
80 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` |