seo: improve metadata base and sitemap resilience
Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { locales } from "@/i18n/locales";
|
||||
import { getBaseUrl } from "@/lib/seo";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
|
||||
|
||||
export type SitemapEntry = {
|
||||
url: string;
|
||||
@@ -49,11 +50,20 @@ export async function getSitemapEntries(): Promise<SitemapEntry[]> {
|
||||
);
|
||||
|
||||
// Projects: for each project slug we publish per locale (same slug)
|
||||
const projects = await prisma.project.findMany({
|
||||
where: { published: true },
|
||||
select: { slug: true, updatedAt: true },
|
||||
orderBy: { updatedAt: "desc" },
|
||||
});
|
||||
let projects: Array<{ slug: string; updatedAt: Date | null }> = [];
|
||||
try {
|
||||
projects = await prisma.project.findMany({
|
||||
where: { published: true },
|
||||
select: { slug: true, updatedAt: true },
|
||||
orderBy: { updatedAt: "desc" },
|
||||
});
|
||||
} catch (error) {
|
||||
// If DB isn't ready/migrated yet, still serve a valid sitemap for static pages.
|
||||
if (error instanceof PrismaClientKnownRequestError && (error.code === "P2021" || error.code === "P2022")) {
|
||||
return staticEntries;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const projectEntries: SitemapEntry[] = projects.flatMap((p) => {
|
||||
const lastModified = (p.updatedAt ?? new Date()).toISOString();
|
||||
|
||||
Reference in New Issue
Block a user