articles/[slug]: drop Stay Updated sidebar card; related fallback to latest
Empty Related Articles bug on /articles/<slug> traced to two issues: - Two rows were imported with category="industry" instead of the canonical "Industry News", so the category-match query returned zero peers. - The fallback path was missing — getLegacyRelatedArticles now tops up with the latest published rows whenever the category match is short. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -424,17 +424,6 @@ export default function ArticleDetailClient({ article, relatedArticles }: Articl
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Newsletter Signup */}
|
|
||||||
<div className="bg-[#0d1520] border border-[#1e3a5f] p-5">
|
|
||||||
<h3 className="font-heading text-[#e0e0e0] font-bold mb-2">Stay Updated</h3>
|
|
||||||
<p className="font-body text-[#777] text-xs mb-4">
|
|
||||||
Get the latest broadcast engineering news delivered to your inbox.
|
|
||||||
</p>
|
|
||||||
<Link href="/home-page#newsletter" className="btn-subscribe text-xs py-2 px-4 inline-block w-full text-center">
|
|
||||||
Subscribe Free
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Sidebar ad stack — 300x600 + 300x250 rotating */}
|
{/* Sidebar ad stack — 300x600 + 300x250 rotating */}
|
||||||
<SidebarAdStack />
|
<SidebarAdStack />
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -252,21 +252,42 @@ export async function getLegacyRelatedArticles(
|
|||||||
category: string | null,
|
category: string | null,
|
||||||
count: number,
|
count: number,
|
||||||
): Promise<Article[]> {
|
): Promise<Article[]> {
|
||||||
try {
|
const collected: ImportedPostRow[] = [];
|
||||||
let q = client()
|
const seen = new Set<string>([excludeSlug]);
|
||||||
.from("wp_imported_posts")
|
// First pass: same category. Skip when no category recorded.
|
||||||
.select(SELECT_COLS)
|
if (category) {
|
||||||
.eq("status", "published")
|
try {
|
||||||
.neq("wp_slug", excludeSlug)
|
const { data } = await client()
|
||||||
.order("wp_published_at", { ascending: false })
|
.from("wp_imported_posts")
|
||||||
.limit(count);
|
.select(SELECT_COLS)
|
||||||
if (category) q = q.eq("category", category);
|
.eq("status", "published")
|
||||||
const { data, error } = await q;
|
.eq("category", category)
|
||||||
if (error || !data) return [];
|
.neq("wp_slug", excludeSlug)
|
||||||
return (data as ImportedPostRow[]).map((r) => rowToArticle(r));
|
.order("wp_published_at", { ascending: false })
|
||||||
} catch {
|
.limit(count);
|
||||||
return [];
|
for (const row of (data as ImportedPostRow[] | null) || []) {
|
||||||
|
if (!seen.has(row.wp_slug)) { collected.push(row); seen.add(row.wp_slug); }
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
|
// Fallback: top up to `count` with the latest published, excluding what we
|
||||||
|
// already have. Handles tiny categories, orphan rows, and category=null.
|
||||||
|
if (collected.length < count) {
|
||||||
|
try {
|
||||||
|
const { data } = await client()
|
||||||
|
.from("wp_imported_posts")
|
||||||
|
.select(SELECT_COLS)
|
||||||
|
.eq("status", "published")
|
||||||
|
.neq("wp_slug", excludeSlug)
|
||||||
|
.order("wp_published_at", { ascending: false })
|
||||||
|
.limit(count + collected.length + 5);
|
||||||
|
for (const row of (data as ImportedPostRow[] | null) || []) {
|
||||||
|
if (collected.length >= count) break;
|
||||||
|
if (!seen.has(row.wp_slug)) { collected.push(row); seen.add(row.wp_slug); }
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
return collected.map((r) => rowToArticle(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLegacyArticlesBySection(
|
export async function getLegacyArticlesBySection(
|
||||||
|
|||||||
Reference in New Issue
Block a user