Skip to content
Merged
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
Comment thread
Meyanis95 marked this conversation as resolved.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/lib/posts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { CollectionEntry } from 'astro:content';

/*
* Date gating for the `posts` collection, matching Jekyll's `future: false`:
* a post whose `date` is in the future is hidden until the site is rebuilt at
* or after that moment (GH Pages rebuilds on push/merge).
*
* Shared by every consumer of getCollection('posts') so the blog index, the
* homepage latest-posts list, and static path generation all agree.
*
* The comparison is on the full timestamp, not just the calendar day, so a
* post can be scheduled to the hour. Give `date` a time and offset to pin a
* release (e.g. `2026-06-11T07:00:00-04:00` for 7am ET). A bare `YYYY-MM-DD`
* is parsed as midnight UTC, which keeps day-granular scheduling working.
* Note this only gates the static output: a future-dated post still appears
* only once a build actually runs at or after its `date`.
*/
export function isPublished(
post: CollectionEntry<'posts'>,
now: Date = new Date(),
): boolean {
const date =
post.data.date instanceof Date ? post.data.date : new Date(post.data.date);
return date.getTime() <= now.getTime();
}
3 changes: 2 additions & 1 deletion src/pages/blog/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getCollection, render } from 'astro:content';
import DetailPageLayout from '../../layouts/DetailPageLayout.astro';
import ArticleFooter from '../../components/ArticleFooter.astro';
import { jekyllSlugify } from '../../lib/jekyllSlug';
import { isPublished } from '../../lib/posts';

function toISODate(d: string | Date | undefined): string {
if (!d) return '';
Expand All @@ -19,7 +20,7 @@ function toISODate(d: string | Date | undefined): string {

export async function getStaticPaths() {
const entries = await getCollection('posts');
return entries.map((entry) => ({
return entries.filter((entry) => isPublished(entry)).map((entry) => ({
params: { slug: jekyllSlugify(entry.data.title) },
props: { entry },
}));
Expand Down
2 changes: 2 additions & 0 deletions src/pages/blog/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getCollection } from 'astro:content';
import ListPageLayout from '../../layouts/ListPageLayout.astro';
import NextStepCTA from '../../components/NextStepCTA.astro';
import { jekyllSlugify } from '../../lib/jekyllSlug';
import { isPublished } from '../../lib/posts';

function toISODate(d: string | Date | undefined): string {
if (!d) return '';
Expand All @@ -21,6 +22,7 @@ function toISODate(d: string | Date | undefined): string {

const all = await getCollection('posts');
const posts = all
.filter((p) => isPublished(p))
.map((p) => ({
slug: jekyllSlugify(p.data.title),
title: p.data.title,
Expand Down
4 changes: 3 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PipelineAnimation from '../components/PipelineAnimation.astro';
import { getStats } from '../lib/stats';
import { getCollection } from 'astro:content';
import { jekyllSlugify } from '../lib/jekyllSlug';
import { isPublished } from '../lib/posts';
import { findFaq } from '../data/faq';

const stats = await getStats();
Expand All @@ -18,7 +19,8 @@ function toISODate(d: string | Date | undefined): string {
return String(d).slice(0, 10);
}
const allPosts = await getCollection('posts');
const latestPosts = [...allPosts]
const latestPosts = allPosts
.filter((p) => isPublished(p))
.map((p) => ({
slug: jekyllSlugify(p.data.title),
title: p.data.title,
Expand Down
Loading
Loading