Fix: Add ID fallback for news detail route

This commit is contained in:
Carlos (Almeira) 2026-03-26 15:32:08 -05:00
parent 48ad517133
commit eed1bc1b6b

View File

@ -5,17 +5,25 @@ import { GlobalSidebar } from '@/components/AdWrappers';
import { Calendar, User, ArrowLeft } from 'lucide-react';
import Link from 'next/link';
async function fetchPostData(slug: string) {
async function fetchPostData(slugOrId: string) {
try {
const client = await createAdminClient();
const dbId = APPWRITE_ALMEIRA_CONFIG.databaseId;
const res = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [
Query.equal('slug', slug),
// 1. Try by slug
let res = await client.databases.listDocuments(dbId, 'posts', [
Query.equal('slug', slugOrId),
Query.limit(1)
]);
if (res.documents.length === 0) return null;
return res.documents[0];
if (res.documents.length > 0) return res.documents[0];
// 2. Try by $id (fallback)
try {
return await client.databases.getDocument(dbId, 'posts', slugOrId);
} catch (e) {
return null;
}
} catch (e) {
console.error("Post detail fetch error", e);
return null;