From 57099ed1190223eb817940cd944bafdaab100381 Mon Sep 17 00:00:00 2001 From: Ben Smithett Date: Wed, 5 Aug 2020 10:03:32 +1000 Subject: [PATCH] Filter posts from feed if they don't have a valid date --- app/prerender.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/prerender.js b/app/prerender.js index ffcb197..140bd7a 100644 --- a/app/prerender.js +++ b/app/prerender.js @@ -160,19 +160,21 @@ function buildJSONFeedFile(pageProps) { title: feedTitle, home_page_url: siteURL, feed_url: `${siteURL}/feed.json`, - items: items.map(({ PageComponent, urlPath, meta }) => ({ - id: urlPath, - url: `${siteURL}${urlPath}`, - title: meta.title, - date_published: new Date(meta.date).toISOString(), - content_text: ReactDOMServer.renderToStaticMarkup( - // Render with Fela, just in case any components in the page require it - // We don't need to do anything with the results though, because we only want the CSS-free body HTML for our feed - - - - ) - })) + items: items + .filter(({ meta }) => meta.date && dayjs(meta.date).isValid()) + .map(({ PageComponent, urlPath, meta }) => ({ + id: urlPath, + url: `${siteURL}${urlPath}`, + title: meta.title, + date_published: dayjs(meta.date).toISOString(), + content_text: ReactDOMServer.renderToStaticMarkup( + // Render with Fela, just in case any components in the page require it + // We don't need to do anything with the results though, because we only want the CSS-free body HTML for our feed + + + + ) + })) } const outputFilePath = path.resolve(__dirname, '../output/feed.json')