From b9fe8c7f383f7257eb246b71987845c8152e7793 Mon Sep 17 00:00:00 2001 From: Nick Pegg Date: Wed, 11 Oct 2017 22:19:51 -0700 Subject: [PATCH] match posts on year/month too Shouldn't assume that slugs will be globally unique, this enforces month-local uniqueness instead --- src/Post.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Post.js b/src/Post.js index a82bf45..176df92 100644 --- a/src/Post.js +++ b/src/Post.js @@ -24,12 +24,20 @@ class Post extends Component { .then((blob) => { let found = false; for (let post of blob.posts) { + let date = new Date(post.date); + let year = date.getUTCFullYear(); + let month = date.getUTCMonth() + 1; + let slug = post.slug; if (!slug) { slug = slugify(post.title); } - if (slug === this.params.slug) { + if ( + slug === this.params.slug + && year === Number(this.params.year) + && month === Number(this.params.month) + ) { this.setState({post: post}) found = true; break