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
6 changes: 5 additions & 1 deletion app/api/webhooks/crawlproof/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
};

Expand Down
17 changes: 14 additions & 3 deletions lib/blog/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -59,7 +70,7 @@ export async function loadDbPosts(): Promise<Post[]> {
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);
Expand Down Expand Up @@ -89,7 +100,7 @@ export async function findAnyPost(slug: string): Promise<Post | undefined> {
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();
Expand Down
Loading