ticker: query wp_imported_posts (not native_articles) + fallback when 7d window empty
This commit is contained in:
@@ -15,24 +15,38 @@ export async function GET() {
|
||||
|
||||
const cutoff = new Date(Date.now() - 7 * 86400000).toISOString();
|
||||
|
||||
const { data, error } = await sb
|
||||
.from('native_articles')
|
||||
.select('id, slug, title, category, published_at')
|
||||
// Primary source: bb.wp_imported_posts (BB's main article table).
|
||||
let { data, error } = await sb
|
||||
.from('wp_imported_posts')
|
||||
.select('wp_id, wp_slug, title, category, wp_published_at')
|
||||
.eq('status', 'published')
|
||||
.gte('published_at', cutoff)
|
||||
.order('published_at', { ascending: false })
|
||||
.gte('wp_published_at', cutoff)
|
||||
.order('wp_published_at', { ascending: false })
|
||||
.limit(30);
|
||||
|
||||
// Fallback: if the 7-day window is empty, show the 30 most recent
|
||||
// published articles regardless of age so the ticker isn't blank.
|
||||
if (!error && (data?.length ?? 0) === 0) {
|
||||
const recent = await sb
|
||||
.from('wp_imported_posts')
|
||||
.select('wp_id, wp_slug, title, category, wp_published_at')
|
||||
.eq('status', 'published')
|
||||
.order('wp_published_at', { ascending: false })
|
||||
.limit(30);
|
||||
data = recent.data;
|
||||
error = recent.error;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message, items: [] }, { status: 500 });
|
||||
}
|
||||
|
||||
const items = (data || []).map((a) => ({
|
||||
id: a.id,
|
||||
href: `/articles/${a.slug}`,
|
||||
id: String(a.wp_id),
|
||||
href: `/news/${a.wp_slug}`,
|
||||
title: a.title,
|
||||
category: a.category || null,
|
||||
published_at: a.published_at,
|
||||
published_at: a.wp_published_at,
|
||||
}));
|
||||
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user