diff --git a/gatsby-node.js b/gatsby-node.js index 80522283..2525c556 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -76,6 +76,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => { node { fields { slug + date } } } @@ -85,8 +86,9 @@ exports.createPages = async ({ graphql, actions, reporter }) => { ); const posts = blogQueryResult.data.allMarkdownRemark.edges; posts.forEach((edge) => { + console.log(edge.node.fields.date); createPage({ - path: `/blog${edge.node.fields.slug}`, + path: `/blog${edge.node.fields.slug}-${edge.node.fields.date.replace(/[-T:.Z]/g, '-').substring(0, 10)}`, component: blogPostTemplate, context: { slug: edge.node.fields.slug, diff --git a/src/components/Home/Index.jsx b/src/components/Home/Index.jsx index b15b40c9..1b8f8a39 100644 --- a/src/components/Home/Index.jsx +++ b/src/components/Home/Index.jsx @@ -48,7 +48,7 @@ function Index() { return { posttype, title, - path: `/blog${slug}`, + path: `/blog${slug}-${date.replace(/[-T:.Z]/g, "-").substring(0, 10)}`, cover, tags, excerpt, diff --git a/src/templates/Blog.jsx b/src/templates/Blog.jsx index 07d03dd0..35592fc6 100644 --- a/src/templates/Blog.jsx +++ b/src/templates/Blog.jsx @@ -46,7 +46,9 @@ export default class Blog extends React.Component { diff --git a/src/templates/BlogList.jsx b/src/templates/BlogList.jsx index ad95bff8..cc97e3d2 100644 --- a/src/templates/BlogList.jsx +++ b/src/templates/BlogList.jsx @@ -72,7 +72,9 @@ function BlogList({ data, pageContext, location }) { return { posttype, title, - path: `${prefix}${slug}`, + path: `${prefix}${slug}-${date + .replace(/[-T:.Z]/g, "-") + .substring(0, 10)}`, cover, tags, excerpt,