Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/build-rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()

const blogPosts = Object.keys(postsTable)
Expand Down
15 changes: 14 additions & 1 deletion src/lib/notion/getBlogIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' : ''}`
Expand Down Expand Up @@ -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(() => {})
}
Expand Down