seo: improve metadata base and sitemap resilience

Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
Cursor Agent
2026-01-15 10:11:02 +00:00
parent 5b67c457d7
commit d60f875793
2 changed files with 17 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import { Inter } from "next/font/google";
import React from "react"; import React from "react";
import ClientProviders from "./components/ClientProviders"; import ClientProviders from "./components/ClientProviders";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import { getBaseUrl } from "@/lib/seo";
const inter = Inter({ const inter = Inter({
variable: "--font-inter", variable: "--font-inter",
@@ -30,6 +31,7 @@ export default async function RootLayout({
} }
export const metadata: Metadata = { export const metadata: Metadata = {
metadataBase: new URL(getBaseUrl()),
title: "Dennis Konkol | Portfolio", title: "Dennis Konkol | Portfolio",
description: description:
"Portfolio of Dennis Konkol, a student and software engineer based in Osnabrück, Germany. Passionate about technology, coding, and solving real-world problems.", "Portfolio of Dennis Konkol, a student and software engineer based in Osnabrück, Germany. Passionate about technology, coding, and solving real-world problems.",

View File

@@ -1,6 +1,7 @@
import { prisma } from "@/lib/prisma"; import { prisma } from "@/lib/prisma";
import { locales } from "@/i18n/locales"; import { locales } from "@/i18n/locales";
import { getBaseUrl } from "@/lib/seo"; import { getBaseUrl } from "@/lib/seo";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
export type SitemapEntry = { export type SitemapEntry = {
url: string; url: string;
@@ -49,11 +50,20 @@ export async function getSitemapEntries(): Promise<SitemapEntry[]> {
); );
// Projects: for each project slug we publish per locale (same slug) // Projects: for each project slug we publish per locale (same slug)
const projects = await prisma.project.findMany({ let projects: Array<{ slug: string; updatedAt: Date | null }> = [];
where: { published: true }, try {
select: { slug: true, updatedAt: true }, projects = await prisma.project.findMany({
orderBy: { updatedAt: "desc" }, 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 projectEntries: SitemapEntry[] = projects.flatMap((p) => {
const lastModified = (p.updatedAt ?? new Date()).toISOString(); const lastModified = (p.updatedAt ?? new Date()).toISOString();