Upgrade to latest canary
This commit is contained in:
parent
1eb4820ba3
commit
b7d1dbf4e1
3 changed files with 867 additions and 143 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
const _ = require("lodash")
|
const _ = require("lodash");
|
||||||
const Promise = require("bluebird")
|
const Promise = require("bluebird");
|
||||||
const path = require("path")
|
const path = require("path");
|
||||||
const select = require(`unist-util-select`)
|
const select = require(`unist-util-select`);
|
||||||
const fs = require(`fs-extra`)
|
const fs = require(`fs-extra`);
|
||||||
|
|
||||||
exports.createPages = ({ args }) => {
|
exports.createPages = ({ graphql, actionCreators }) => {
|
||||||
const { graphql } = args
|
const { upsertPage } = actionCreators;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const pages = []
|
const pages = [];
|
||||||
const blogPost = path.resolve("templates/template-blog-post.js")
|
const blogPost = path.resolve("templates/template-blog-post.js");
|
||||||
graphql(
|
graphql(
|
||||||
`
|
`
|
||||||
{
|
{
|
||||||
|
|
@ -24,43 +24,39 @@ exports.createPages = ({ args }) => {
|
||||||
`
|
`
|
||||||
).then(result => {
|
).then(result => {
|
||||||
if (result.errors) {
|
if (result.errors) {
|
||||||
console.log(result.errors)
|
console.log(result.errors);
|
||||||
reject(result.errors)
|
reject(result.errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create blog posts pages.
|
// Create blog posts pages.
|
||||||
_.each(result.data.allMarkdownRemark.edges, edge => {
|
_.each(result.data.allMarkdownRemark.edges, edge => {
|
||||||
pages.push({
|
upsertPage({
|
||||||
path: edge.node.slug, // required
|
path: edge.node.slug, // required
|
||||||
component: blogPost,
|
component: blogPost,
|
||||||
context: {
|
context: {
|
||||||
slug: edge.node.slug,
|
slug: edge.node.slug,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
resolve(pages)
|
resolve();
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Add custom url pathname for blog posts.
|
// Add custom url pathname for blog posts.
|
||||||
exports.modifyAST = ({ args }) => {
|
exports.onNodeCreate = ({ node, actionCreators, getNode }) => {
|
||||||
const { ast } = args
|
const { updateNode } = actionCreators;
|
||||||
const files = select(ast, "File")
|
if (node.type === `File` && typeof node.slug === "undefined") {
|
||||||
files.forEach(file => {
|
const parsedFilePath = path.parse(node.relativePath);
|
||||||
if (file.extension !== `md`) {
|
const slug = `/${parsedFilePath.dir}/`;
|
||||||
return
|
node.slug = slug;
|
||||||
}
|
updateNode(node);
|
||||||
const parsedFilePath = path.parse(file.relativePath)
|
} else if (
|
||||||
console.log(parsedFilePath)
|
node.type === `MarkdownRemark` && typeof node.slug === "undefined"
|
||||||
const slug = `/${parsedFilePath.dir}/`
|
) {
|
||||||
console.log(slug)
|
const fileNode = getNode(node.parent);
|
||||||
file.slug = slug
|
node.slug = fileNode.slug;
|
||||||
const markdownNode = select(file, `MarkdownRemark`)[0]
|
updateNode(node);
|
||||||
if (markdownNode) {
|
}
|
||||||
markdownNode.slug = slug
|
};
|
||||||
}
|
|
||||||
})
|
|
||||||
return files
|
|
||||||
}
|
|
||||||
|
|
|
||||||
36
package.json
36
package.json
|
|
@ -7,24 +7,24 @@
|
||||||
"url": "https://github.com/gatsbyjs/gatsby-starter-blog/issues"
|
"url": "https://github.com/gatsbyjs/gatsby-starter-blog/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gatsby": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-link": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-link": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-parser-remark": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-parser-remark": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-parser-sharp": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-parser-sharp": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-plugin-google-analytics": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-plugin-google-analytics": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-plugin-manifest": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-plugin-manifest": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-plugin-offline": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-plugin-offline": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-plugin-preact": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-plugin-preact": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-plugin-sharp": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-plugin-sharp": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-source-filesystem": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-source-filesystem": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-filesystem": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-filesystem": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-remark": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-remark": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-remark-copy-linked-files": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-remark-copy-linked-files": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-remark-prismjs": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-remark-prismjs": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-remark-responsive-iframe": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-remark-responsive-iframe": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-remark-responsive-image": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-remark-responsive-image": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-remark-smartypants": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-remark-smartypants": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"gatsby-typegen-sharp": "1.0.0-alpha12-alpha.dbf1a599",
|
"gatsby-typegen-sharp": "1.0.0-alpha12-alpha.1fdb9004",
|
||||||
"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",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue