diff --git a/src/lib/build-rss.ts b/src/lib/build-rss.ts index 6b7c5b40..4b5c9c75 100644 --- a/src/lib/build-rss.ts +++ b/src/lib/build-rss.ts @@ -71,7 +71,7 @@ function createRSS(blogPosts = []) { } async function main() { - const postsTable = await getBlogIndex(true) + const postsTable = await getBlogIndex(true, false) const neededAuthors = new Set() const blogPosts = Object.keys(postsTable) diff --git a/src/lib/notion/getBlogIndex.ts b/src/lib/notion/getBlogIndex.ts index ae737867..9bf3477c 100644 --- a/src/lib/notion/getBlogIndex.ts +++ b/src/lib/notion/getBlogIndex.ts @@ -6,7 +6,10 @@ import { getPostPreview } from './getPostPreview' import { readFile, writeFile } from '../fs-helpers' import { BLOG_INDEX_ID, BLOG_INDEX_CACHE } from './server-constants' -export default async function getBlogIndex(previews = true) { +export default async function getBlogIndex( + previews = true, + include_future_posts = false +) { let postsTable: any = null const useCache = process.env.USE_CACHE === 'true' const cacheFile = `${BLOG_INDEX_CACHE}${previews ? '_previews' : ''}` @@ -77,6 +80,16 @@ export default async function getBlogIndex(previews = true) { ) } + if (!include_future_posts) { + const nowDate = Date.now() + + Object.keys(postsTable).forEach(slug => { + if (postsTable[slug].Date > nowDate) { + delete postsTable[slug] + } + }) + } + if (useCache) { writeFile(cacheFile, JSON.stringify(postsTable), 'utf8').catch(() => {}) }