Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Reserved Post #59

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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