Skip to content

Commit

Permalink
Fix last updated bug
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamminj committed Sep 25, 2020
1 parent 534fe29 commit 0cc29f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pages/blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const getStaticProps: GetStaticProps = async () => {
for (let postFile of postFiles) {
try {
const slug = slugifyPost(postFile)
const { frontmatter, body } = getPostBySlug(slug)
const { frontmatter } = getPostBySlug(slug)

// Don't add the post to the list if it's a WIP
if (frontmatter.draft) continue
Expand All @@ -91,6 +91,7 @@ export const getStaticProps: GetStaticProps = async () => {
.sort((a, b) => compareDesc(a.date, b.date))
.map(p => ({
...p,
lastUpdated: format(p.date, 'yyyy-MM-dd'),
// We add the date formatting _after_ sorting so that we can accurately sort
// by date.
date: format(p.date, 'yyyy-MM-dd'),
Expand Down
5 changes: 3 additions & 2 deletions pages/blog/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,15 @@ export const getStaticProps: GetPostPageStaticProps = async ctx => {
rehypePlugins: [prism],
})

const displayedDate = frontmatter.lastUpdated || frontmatter.date
const { lastUpdated, ...frontmatterProps } = frontmatter
const displayedDate = lastUpdated || frontmatter.date

return {
props: {
slug,
mdxContent,
frontmatter: {
...frontmatter,
...frontmatterProps,
date: format(displayedDate, 'MM-dd-yyyy'),
},
...imageProps,
Expand Down

0 comments on commit 0cc29f3

Please sign in to comment.