Upgrade to 1.0-alpha16
This commit is contained in:
parent
11e1d019cb
commit
4f47229cb6
4 changed files with 38 additions and 36 deletions
|
|
@ -9,7 +9,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const pages = []
|
const pages = []
|
||||||
const blogPost = path.resolve("./src/templates/template-blog-post.js")
|
const blogPost = path.resolve("./src/templates/blog-post.js")
|
||||||
resolve(
|
resolve(
|
||||||
graphql(
|
graphql(
|
||||||
`
|
`
|
||||||
|
|
@ -17,11 +17,13 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
||||||
allMarkdownRemark(limit: 1000) {
|
allMarkdownRemark(limit: 1000) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
fields {
|
||||||
slug
|
slug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
`
|
`
|
||||||
).then(result => {
|
).then(result => {
|
||||||
if (result.errors) {
|
if (result.errors) {
|
||||||
|
|
@ -32,10 +34,10 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
||||||
// Create blog posts pages.
|
// Create blog posts pages.
|
||||||
_.each(result.data.allMarkdownRemark.edges, edge => {
|
_.each(result.data.allMarkdownRemark.edges, edge => {
|
||||||
upsertPage({
|
upsertPage({
|
||||||
path: edge.node.slug, // required
|
path: edge.node.fields.slug, // required
|
||||||
component: blogPost,
|
component: blogPost,
|
||||||
context: {
|
context: {
|
||||||
slug: edge.node.slug,
|
slug: edge.node.fields.slug,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -44,20 +46,19 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add custom url pathname for blog posts.
|
// Add custom slug for blog posts to both File and MarkdownRemark nodes.
|
||||||
exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
|
exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
|
||||||
const { updateNode } = boundActionCreators
|
const { addFieldToNode } = boundActionCreators
|
||||||
if (node.internal.type === `File` && typeof node.slug === "undefined") {
|
if (node.internal.type === `File`) {
|
||||||
const parsedFilePath = path.parse(node.relativePath)
|
const parsedFilePath = path.parse(node.relativePath)
|
||||||
const slug = `/${parsedFilePath.dir}/`
|
const slug = `/${parsedFilePath.dir}/`
|
||||||
node.slug = slug
|
addFieldToNode({ node, fieldName: `slug`, fieldValue: slug })
|
||||||
updateNode(node)
|
} else if (node.internal.type === `MarkdownRemark`) {
|
||||||
} else if (
|
|
||||||
node.internal.type === `MarkdownRemark` &&
|
|
||||||
typeof node.slug === "undefined"
|
|
||||||
) {
|
|
||||||
const fileNode = getNode(node.parent)
|
const fileNode = getNode(node.parent)
|
||||||
node.slug = fileNode.slug
|
addFieldToNode({
|
||||||
updateNode(node)
|
node,
|
||||||
|
fieldName: `slug`,
|
||||||
|
fieldValue: fileNode.fields.slug,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
package.json
30
package.json
|
|
@ -7,21 +7,21 @@
|
||||||
"url": "https://github.com/gatsbyjs/gatsby-starter-blog/issues"
|
"url": "https://github.com/gatsbyjs/gatsby-starter-blog/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gatsby": "canary",
|
"gatsby": "next",
|
||||||
"gatsby-link": "canary",
|
"gatsby-link": "next",
|
||||||
"gatsby-transformer-remark": "canary",
|
"gatsby-transformer-remark": "next",
|
||||||
"gatsby-transformer-sharp": "canary",
|
"gatsby-transformer-sharp": "next",
|
||||||
"gatsby-plugin-google-analytics": "canary",
|
"gatsby-plugin-google-analytics": "next",
|
||||||
"gatsby-plugin-manifest": "canary",
|
"gatsby-plugin-manifest": "next",
|
||||||
"gatsby-plugin-offline": "canary",
|
"gatsby-plugin-offline": "next",
|
||||||
"gatsby-plugin-preact": "canary",
|
"gatsby-plugin-preact": "next",
|
||||||
"gatsby-plugin-sharp": "canary",
|
"gatsby-plugin-sharp": "next",
|
||||||
"gatsby-source-filesystem": "canary",
|
"gatsby-source-filesystem": "next",
|
||||||
"gatsby-remark-copy-linked-files": "canary",
|
"gatsby-remark-copy-linked-files": "next",
|
||||||
"gatsby-remark-prismjs": "canary",
|
"gatsby-remark-prismjs": "next",
|
||||||
"gatsby-remark-responsive-iframe": "canary",
|
"gatsby-remark-responsive-iframe": "next",
|
||||||
"gatsby-remark-responsive-image": "canary",
|
"gatsby-remark-responsive-image": "next",
|
||||||
"gatsby-remark-smartypants": "canary",
|
"gatsby-remark-smartypants": "next",
|
||||||
"lodash": "^4.15.0",
|
"lodash": "^4.15.0",
|
||||||
"moment": "^2.14.1",
|
"moment": "^2.14.1",
|
||||||
"react-helmet": "^4.0.0",
|
"react-helmet": "^4.0.0",
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class BlogIndex extends React.Component {
|
||||||
marginBottom: rhythm(1 / 4),
|
marginBottom: rhythm(1 / 4),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Link style={{ boxShadow: "none" }} to={post.node.slug}>
|
<Link style={{ boxShadow: "none" }} to={post.node.fields.slug}>
|
||||||
{post.node.frontmatter.title}
|
{post.node.frontmatter.title}
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
|
|
@ -59,7 +59,9 @@ query IndexQuery {
|
||||||
allMarkdownRemark {
|
allMarkdownRemark {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
fields {
|
||||||
slug
|
slug
|
||||||
|
}
|
||||||
frontmatter {
|
frontmatter {
|
||||||
title
|
title
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,10 @@ import get from "lodash/get"
|
||||||
import Bio from "../components/Bio"
|
import Bio from "../components/Bio"
|
||||||
import { rhythm, scale } from "../utils/typography"
|
import { rhythm, scale } from "../utils/typography"
|
||||||
|
|
||||||
class BlogPostRoute extends React.Component {
|
class BlogPostTemplate extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const post = this.props.data.markdownRemark
|
const post = this.props.data.markdownRemark
|
||||||
const siteTitle = get(this.props, "data.site.siteMetadata.title")
|
const siteTitle = get(this.props, "data.site.siteMetadata.title")
|
||||||
// console.log(this.props)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -38,7 +37,7 @@ class BlogPostRoute extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BlogPostRoute
|
export default BlogPostTemplate
|
||||||
|
|
||||||
export const pageQuery = graphql`
|
export const pageQuery = graphql`
|
||||||
query BlogPostByPath($slug: String!) {
|
query BlogPostByPath($slug: String!) {
|
||||||
|
|
@ -48,7 +47,7 @@ export const pageQuery = graphql`
|
||||||
author
|
author
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
markdownRemark(slug: { eq: $slug }) {
|
markdownRemark(fields: { slug: { eq: $slug }}) {
|
||||||
id
|
id
|
||||||
html
|
html
|
||||||
frontmatter {
|
frontmatter {
|
||||||
Loading…
Add table
Add a link
Reference in a new issue