Extract relative permalinks from Wordpress posts for use as gatsby paths

This commit is contained in:
ponas committed 2019-01-27 11:39:55 +01:00
1 parent 051a45facb
commit cf160faf96
2 files changed
+18 -4

No files matched your search

+13 -1
View File
@@ -60,6 +60,9 @@ exports.createPages = ({ actions, graphql }) => {
id
slug
status
fields {
link
}
}
}
}
@@ -86,7 +89,7 @@ exports.createPages = ({ actions, graphql }) => {
_.each(posts, ({ node: post }) => {
// Create the Gatsby page for this WordPress post
createPage({
path: `/${post.slug}/`,
path: post.fields.link,
component: postTemplate,
context: {
id: post.id,
@@ -219,4 +222,13 @@ exports.onCreateNode = ({ node, actions, getNode }) => {
value,
})
}
if (node.internal.type === 'wordpress__POST') {
const link = new URL(node.link).pathname
createNodeField({
node,
name: `link`,
value: link,
})
}
}