feat: publish scheduled posts on their pubDate with a daily build

This commit is contained in:
Lorenzo Iovino 2026-09-29 00:17:42 +02:00
parent c8e0446216
commit c6b3007995
6 changed files with 25 additions and 4 deletions

13
src/utils/posts.ts Normal file
View file

@ -0,0 +1,13 @@
import type { CollectionEntry } from "astro:content";
type BlogPost = CollectionEntry<"blog">;
// A post with a future pubDate stays in the repo but is left out of the build
// until that day (Rome calendar day, not UTC): the scheduled CI build publishes
// it. `astro dev` shows everything so scheduled posts can be previewed.
export function isPublished(post: BlogPost, now: Date = new Date()): boolean {
if (post.data.draft) return false;
if (import.meta.env.DEV) return true;
const today = new Intl.DateTimeFormat("en-CA", { timeZone: "Europe/Rome" }).format(now);
return post.data.pubDate.toISOString().slice(0, 10) <= today;
}