diff --git a/app/api/webhooks/crawlproof/route.ts b/app/api/webhooks/crawlproof/route.ts index d4180de0..849dea64 100644 --- a/app/api/webhooks/crawlproof/route.ts +++ b/app/api/webhooks/crawlproof/route.ts @@ -87,6 +87,10 @@ export async function POST(req: NextRequest) { } const { post } = parsed; + // Use the article's own publication date as published_at so the blog + // shows the real authorship date rather than the server-clock time at + // ingest (which can be skewed if the server's system clock is ahead). + const publishedAt = post.published_at ?? new Date().toISOString(); const row = { source: "crawlproof", source_id: post.id, @@ -98,7 +102,7 @@ export async function POST(req: NextRequest) { image_url: post.featured_image?.url ?? null, tags: post.tags, source_created_at: post.published_at, - published_at: new Date().toISOString(), + published_at: publishedAt, updated_at: new Date().toISOString(), }; diff --git a/lib/blog/posts.ts b/lib/blog/posts.ts index 8fb115ea..8d36f377 100644 --- a/lib/blog/posts.ts +++ b/lib/blog/posts.ts @@ -32,14 +32,25 @@ type BlogPostRow = { content_markdown: string | null; image_url: string | null; published_at: string; + source_created_at: string | null; source: string; }; +// Resolve the best date string (YYYY-MM-DD) for a post row. +// Prefer source_created_at (the date the article was actually written/ +// published by the autoblog source) over published_at (which reflects +// the server clock at ingest time and may be skewed into the future +// if the server's system clock is ahead of wall-clock time). +function resolveDate(row: BlogPostRow): string { + const candidate = row.source_created_at ?? row.published_at; + return candidate.slice(0, 10); +} + function rowToPost(row: BlogPostRow): Post { return { slug: row.slug, title: row.title, - date: row.published_at.slice(0, 10), + date: resolveDate(row), excerpt: row.meta_description ?? "", body: "", html: row.content_html, @@ -59,7 +70,7 @@ export async function loadDbPosts(): Promise { const { data, error } = await sb .from("blog_posts") .select( - "slug, title, meta_description, content_html, content_markdown, image_url, published_at, source", + "slug, title, meta_description, content_html, content_markdown, image_url, published_at, source_created_at, source", ) .order("published_at", { ascending: false }) .limit(200); @@ -89,7 +100,7 @@ export async function findAnyPost(slug: string): Promise { const { data } = await sb .from("blog_posts") .select( - "slug, title, meta_description, content_html, content_markdown, image_url, published_at, source", + "slug, title, meta_description, content_html, content_markdown, image_url, published_at, source_created_at, source", ) .eq("slug", slug) .maybeSingle();