Skip to content

Commit 14d0ef4

Browse files
authored
Fixed off-by-one error for formatted dates (#10848)
1 parent c8da416 commit 14d0ef4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

www/gatsby-node.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,14 @@ exports.onCreateNode = ({node, boundActionCreators, getNode}) => {
178178
// Their slugs follow a pattern: /blog/<year>/<month>/<day>/<slug>.html
179179
// The date portion comes from the file name: <date>-<title>.md
180180
const match = BLOG_POST_FILENAME_REGEX.exec(relativePath);
181-
if (match) {
182-
slug = `/blog/${match[1]}/${match[2]}/${match[3]}/${match[4]}.html`;
183-
}
181+
const year = match[1];
182+
const month = match[2];
183+
const day = match[3];
184+
const filename = match[4];
185+
186+
slug = `/blog/${year}/${month}/${day}/${filename}.html`;
184187

185-
const date = new Date(match[1], match[2], match[3]);
188+
const date = new Date(year, month - 1, day);
186189

187190
// Blog posts are sorted by date and display the date in their header.
188191
createNodeField({

0 commit comments

Comments
 (0)