From 74434a439a63968e807cb40e6c9ded2ff599a28b Mon Sep 17 00:00:00 2001 From: Wataru Manji Date: Sun, 28 Feb 2021 21:44:48 +0900 Subject: [PATCH 1/2] Enable Reserved Post --- src/lib/build-rss.ts | 2 +- src/lib/notion/getBlogIndex.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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..24b2578c 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,17 @@ export default async function getBlogIndex(previews = true) { ) } + if (!include_future_posts) { + const nowDate = Date.now() + postsTable = Object.keys(postsTable) + .map(slug => { + const post = postsTable[slug] + if (post.Date > nowDate) return null + return post + }) + .filter(Boolean) + } + if (useCache) { writeFile(cacheFile, JSON.stringify(postsTable), 'utf8').catch(() => {}) } From a766f3ee1813cb0c6506566bdd86f75ace94ecfb Mon Sep 17 00:00:00 2001 From: Wataru Manji Date: Sun, 28 Feb 2021 22:42:40 +0900 Subject: [PATCH 2/2] Fixed output to Object --- src/lib/notion/getBlogIndex.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/notion/getBlogIndex.ts b/src/lib/notion/getBlogIndex.ts index 24b2578c..9bf3477c 100644 --- a/src/lib/notion/getBlogIndex.ts +++ b/src/lib/notion/getBlogIndex.ts @@ -82,13 +82,12 @@ export default async function getBlogIndex( if (!include_future_posts) { const nowDate = Date.now() - postsTable = Object.keys(postsTable) - .map(slug => { - const post = postsTable[slug] - if (post.Date > nowDate) return null - return post - }) - .filter(Boolean) + + Object.keys(postsTable).forEach(slug => { + if (postsTable[slug].Date > nowDate) { + delete postsTable[slug] + } + }) } if (useCache) {