seo: improve metadata base and sitemap resilience
Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
@@ -4,6 +4,7 @@ import { Inter } from "next/font/google";
|
||||
import React from "react";
|
||||
import ClientProviders from "./components/ClientProviders";
|
||||
import { cookies } from "next/headers";
|
||||
import { getBaseUrl } from "@/lib/seo";
|
||||
|
||||
const inter = Inter({
|
||||
variable: "--font-inter",
|
||||
@@ -30,6 +31,7 @@ export default async function RootLayout({
|
||||
}
|
||||
|
||||
export const metadata: Metadata = {
|
||||
metadataBase: new URL(getBaseUrl()),
|
||||
title: "Dennis Konkol | Portfolio",
|
||||
description:
|
||||
"Portfolio of Dennis Konkol, a student and software engineer based in Osnabrück, Germany. Passionate about technology, coding, and solving real-world problems.",
|
||||
|
||||
@@ -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