Upgrade to alpha-2

This commit is contained in:
Kyle Mathews 2016-09-20 22:23:54 -07:00
parent 94a2ab7ea3
commit 640be90860
12 changed files with 200 additions and 116 deletions

4
.babelrc Normal file
View file

@ -0,0 +1,4 @@
{
"presets": ['react', 'es2015', 'stage-1'],
"plugins": ['add-module-exports']
}

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ node_modules/
public public
.gatsby-context.js .gatsby-context.js
.DS_Store .DS_Store
.intermediate-representation/

View file

@ -1,5 +1,4 @@
import React from 'react' import React from 'react'
import { config } from 'config'
import { rhythm } from 'utils/typography' import { rhythm } from 'utils/typography'
import { prefixLink } from 'gatsby-helpers' import { prefixLink } from 'gatsby-helpers'
import profilePic from './profile-pic.jpg' import profilePic from './profile-pic.jpg'
@ -14,7 +13,7 @@ class Bio extends React.Component {
> >
<img <img
src={prefixLink(profilePic)} src={prefixLink(profilePic)}
alt={`author ${config.authorName}`} alt={`author name`}
style={{ style={{
float: 'left', float: 'left',
marginRight: rhythm(1/4), marginRight: rhythm(1/4),
@ -23,7 +22,7 @@ class Bio extends React.Component {
height: rhythm(2), height: rhythm(2),
}} }}
/> />
Written by <strong>{config.authorName}</strong> who lives and works in San Francisco building useful things. <a href="https://twitter.com/kylemathews">You should follow him on Twitter</a> Written by <strong>TODO author name</strong> who lives and works in TODO San Francisco building useful things. <a href="https://twitter.com/kylemathews">You should follow him on Twitter</a>
</p> </p>
) )
} }

View file

@ -1,37 +1,20 @@
import React from 'react' const React = require('react')
import { Link } from 'react-router' const { Link } = require('react-router')
import { prefixLink } from 'gatsby-helpers'
import { prune, include as includes } from 'underscore.string'
import find from 'lodash/find'
import { rhythm, fontSizeToMS } from 'utils/typography'
class ReadNext extends React.Component { const { rhythm, adjustFontSizeToMSValue } = require('utils/typography')
const Component = React.createClass({
render () { render () {
const { pages, post } = this.props const { nextPost } = this.props
const { readNext } = post
let nextPost
if (readNext) {
nextPost = find(pages, (page) =>
includes(page.path, readNext)
)
}
if (!nextPost) { if (!nextPost) {
return React.createElement('noscript', null) return null
} else { } else {
nextPost = find(pages, (page) =>
includes(page.path, readNext.slice(1, -1))
)
// Create pruned version of the body.
const html = nextPost.data.body
const body = prune(html.replace(/<[^>]*>/g, ''), 200)
return ( return (
<div> <div>
<h6 <h6
style={{ style={{
...adjustFontSizeToMSValue(-0.5),
margin: 0, margin: 0,
fontSize: fontSizeToMS(-0.5).fontSize,
lineHeight: fontSizeToMS(-0.5).lineHeight,
letterSpacing: -0.25, letterSpacing: -0.25,
}} }}
> >
@ -39,32 +22,32 @@ class ReadNext extends React.Component {
</h6> </h6>
<h3 <h3
style={{ style={{
marginTop: 0, margin: 0,
marginBottom: rhythm(1/4),
}} }}
> >
<Link <Link
to={{ to={nextPost.path}
pathname: prefixLink(nextPost.path),
query: {
readNext: true,
},
}}
> >
{nextPost.data.title} {nextPost.frontmatter.title}
</Link> </Link>
</h3> </h3>
<p>{body}</p> <p>{nextPost.excerpt}</p>
<hr /> <hr />
</div> </div>
) )
} }
} }
} })
ReadNext.propTypes = { export default Component
post: React.PropTypes.object.isRequired,
pages: React.PropTypes.array, export const query = `
} readNext {
id
excerpt(pruneLength: 200)
frontmatter {
title
}
}
`
export default ReadNext

10
gatsby-config.js Normal file
View file

@ -0,0 +1,10 @@
const config = {
siteMetadata: {
title: 'Gatsby Starter Blog',
author: 'Kyle Mathews',
homeCity: 'San Francisco',
},
sources: `${__dirname}/pages/`,
}
export default config

46
gatsby-node.js Normal file
View file

@ -0,0 +1,46 @@
import _ from 'lodash'
import Promise from 'bluebird'
import path from 'path'
exports.rewritePath = (parsedFilePath, metadata) => {
if (parsedFilePath.ext === 'md') {
return `/${parsedFilePath.dirname.split('---')[1]}/`
}
}
exports.createPages = ({ graphql }) => (
new Promise((resolve, reject) => {
const pages = []
const blogPost = path.resolve('./page-templates/blog-post.js')
graphql(`
{
allMarkdown(first: 1000) {
edges {
node {
path
}
}
}
}
`)
.then(result => {
if (result.errors) {
console.log(result.errors)
reject(result.errors)
}
// Create blog posts pages.
_.each(result.data.allMarkdown.edges, (edge) => {
if (edge.node.path !== '/404/') {
pages.push({
path: edge.node.path,
component: blogPost,
})
}
})
console.log(pages)
resolve(pages)
})
})
)

13
html.js
View file

@ -3,8 +3,8 @@ import DocumentTitle from 'react-document-title'
import { prefixLink } from 'gatsby-helpers' import { prefixLink } from 'gatsby-helpers'
import { GoogleFont, TypographyStyle } from 'react-typography' import { GoogleFont, TypographyStyle } from 'react-typography'
import typography from './utils/typography' import typography from './utils/typography'
import HTMLScripts from 'html-scripts'
const BUILD_TIME = new Date().getTime() import HTMLStyles from 'html-styles'
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'HTML', displayName: 'HTML',
@ -15,11 +15,6 @@ module.exports = React.createClass({
const { body } = this.props const { body } = this.props
const title = DocumentTitle.rewind() const title = DocumentTitle.rewind()
let css
if (process.env.NODE_ENV === 'production') {
css = <style dangerouslySetInnerHTML={{ __html: require('!raw!./public/styles.css') }} />
}
return ( return (
<html lang="en"> <html lang="en">
<head> <head>
@ -32,11 +27,11 @@ module.exports = React.createClass({
<title>{title}</title> <title>{title}</title>
<TypographyStyle typography={typography} /> <TypographyStyle typography={typography} />
<GoogleFont typography={typography} /> <GoogleFont typography={typography} />
{css} <HTMLStyles />
</head> </head>
<body className="landing-page"> <body className="landing-page">
<div id="react-mount" dangerouslySetInnerHTML={{ __html: body }} /> <div id="react-mount" dangerouslySetInnerHTML={{ __html: body }} />
<script src={prefixLink(`/bundle.js?t=${BUILD_TIME}`)} /> <HTMLScripts scripts={this.props.scripts} />
</body> </body>
</html> </html>
) )

View file

@ -3,7 +3,6 @@ import { Link } from 'react-router'
import { Container } from 'react-responsive-grid' import { Container } from 'react-responsive-grid'
import { prefixLink } from 'gatsby-helpers' import { prefixLink } from 'gatsby-helpers'
import { rhythm, adjustFontSizeToMSValue } from 'utils/typography' import { rhythm, adjustFontSizeToMSValue } from 'utils/typography'
import { config } from 'config'
class Template extends React.Component { class Template extends React.Component {
render () { render () {
@ -26,7 +25,7 @@ class Template extends React.Component {
}} }}
to={prefixLink('/')} to={prefixLink('/')}
> >
{config.blogTitle} {'TODO insert blog title here from query'}
</Link> </Link>
</h1> </h1>
) )
@ -46,7 +45,7 @@ class Template extends React.Component {
}} }}
to={prefixLink('/')} to={prefixLink('/')}
> >
{config.blogTitle} {'insert blog title here'}
</Link> </Link>
</h3> </h3>
) )

View file

@ -7,7 +7,7 @@
"url": "https://github.com/gatsbyjs/gatsby-starter-blog/issues" "url": "https://github.com/gatsbyjs/gatsby-starter-blog/issues"
}, },
"dependencies": { "dependencies": {
"gatsby": "^0.12.6", "gatsby": "1.0.0-alpha2",
"lodash": "^4.15.0", "lodash": "^4.15.0",
"moment": "^2.14.1", "moment": "^2.14.1",
"react-document-title": "^2.0.2", "react-document-title": "^2.0.2",

View file

@ -0,0 +1,71 @@
import React from 'react'
import DocumentTitle from 'react-document-title'
import { Link } from 'react-router'
import get from 'lodash/get'
import { rhythm, adjustFontSizeToMSValue } from 'utils/typography'
import ReadNext from '../components/ReadNext'
//import { query } from '../components/ReadNext'
import Bio from 'components/Bio'
const query = `
readNext {
path
excerpt(pruneLength: 200)
frontmatter {
title
}
}
`
class BlogPostRoute extends React.Component {
render () {
const post = this.props.data.markdown
const siteTitle = get(this.props, 'data.site.siteMetadata.title')
return (
<DocumentTitle title={`${post.frontmatter.title} | ${siteTitle}`}>
<div>
<h1>{post.frontmatter.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.bodyHTML }} />
<p
style={{
...adjustFontSizeToMSValue(-1/5),
display: 'block',
marginBottom: rhythm(1),
}}
>
Posted TODO DATE
</p>
<hr
style={{
marginBottom: rhythm(1),
}}
/>
<ReadNext nextPost={post.frontmatter.readNext} />
<Bio />
</div>
</DocumentTitle>
)
}
}
export default BlogPostRoute
export const pageQuery = `
query BlogPostByPath($path: String!) {
site {
siteMetadata {
title
author
}
}
markdown(path: $path) {
id
bodyHTML
frontmatter {
${query}
title
#date(formatString: "MMMM DD, YYYY")
}
}
}
`

View file

@ -1,38 +1,39 @@
import React from 'react' import React from 'react'
import { Link } from 'react-router' import { Link } from 'react-router'
import sortBy from 'lodash/sortBy' import get from 'lodash/get'
import DocumentTitle from 'react-document-title' import DocumentTitle from 'react-document-title'
import { prefixLink } from 'gatsby-helpers' import { prefixLink } from 'gatsby-helpers'
import { rhythm } from 'utils/typography' import { rhythm } from 'utils/typography'
import access from 'safe-access'
import { config } from 'config'
import include from 'underscore.string/include' import include from 'underscore.string/include'
import Bio from 'components/Bio' import Bio from 'components/Bio'
class BlogIndex extends React.Component { class BlogIndex extends React.Component {
render () { render () {
const pageLinks = [] const pageLinks = []
// Sort pages. const posts = get(this, 'props.data.allMarkdown.edges')
const sortedPages = sortBy(this.props.route.pages, (page) => posts.forEach((post) => {
access(page, 'data.date') if (post.node.path !== '/404/') {
).reverse() const title = get(post, 'node.frontmatter.title') || post.node.path
sortedPages.forEach((page) => {
if (access(page, 'file.ext') === 'md' && !include(page.path, '/404')) {
const title = access(page, 'data.title') || page.path
pageLinks.push( pageLinks.push(
<li <li
key={page.path} key={post.node.path}
style={{ style={{
marginBottom: rhythm(1/4), marginBottom: rhythm(1/4),
}} }}
> >
<Link style={{boxShadow: 'none'}} to={prefixLink(page.path)}>{title}</Link> <Link
style={{boxShadow: 'none'}}
to={prefixLink(post.node.path)}
>
{post.node.frontmatter.title}
</Link>
</li> </li>
) )
} }
}) })
return ( return (
<DocumentTitle title={config.blogTitle}> <DocumentTitle title={get(this, 'props.data.site.siteMetadata.title')}>
<div> <div>
<Bio /> <Bio />
<ul> <ul>
@ -49,3 +50,24 @@ BlogIndex.propTypes = {
} }
export default BlogIndex export default BlogIndex
export const pageQuery = `
{
site {
buildTime
siteMetadata {
title
}
}
allMarkdown(first: 2000) {
edges {
node {
path
frontmatter {
title
}
}
}
}
}
`

View file

@ -1,46 +0,0 @@
import React from 'react'
import moment from 'moment'
import DocumentTitle from 'react-document-title'
import ReadNext from '../components/ReadNext'
import { rhythm } from 'utils/typography'
import { config } from 'config'
import Bio from 'components/Bio'
import '../css/zenburn.css'
class MarkdownWrapper extends React.Component {
render () {
const { route } = this.props
const post = route.page.data
return (
<DocumentTitle title={`${post.title} | ${config.blogTitle}`}>
<div className="markdown">
<h1 style={{marginTop: 0}}>{post.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.body }} />
<em
style={{
display: 'block',
marginBottom: rhythm(2),
}}
>
Posted {moment(post.date).format('MMMM D, YYYY')}
</em>
<hr
style={{
marginBottom: rhythm(2),
}}
/>
<ReadNext post={post} pages={route.pages} />
<Bio />
</div>
</DocumentTitle>
)
}
}
MarkdownWrapper.propTypes = {
route: React.PropTypes.object,
}
export default MarkdownWrapper