66 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-01 12:10:52 -04:00
import type { Metadata, ResolvingMetadata } from "next";
2024-01-11 15:47:19 +00:00
import { getEvent } from "@/lib/server-actions/meta/event";
import { nip19 } from "nostr-tools";
import { getTagValues } from "@/lib/nostr/utils";
2023-11-01 12:10:52 -04:00
export async function generateMetadata(
2023-11-01 12:22:20 -04:00
{ params }: { params: { naddr: string } },
2023-11-01 12:10:52 -04:00
parent: ResolvingMetadata,
): Promise<Metadata> {
2024-01-11 15:47:19 +00:00
const previousImages = (await parent).openGraph?.images || [];
2023-11-01 12:10:52 -04:00
// read route params
const identifier = params.naddr;
2024-01-11 15:47:19 +00:00
const { data, type } = nip19.decode(identifier);
if (type !== "naddr") {
return {
title: "Flockstr Event",
openGraph: {
images: previousImages,
},
};
}
2023-11-01 12:10:52 -04:00
// fetch data
2024-01-11 15:47:19 +00:00
const event = await getEvent(data.kind, data.pubkey, data.identifier);
2023-11-01 12:10:52 -04:00
// optionally access and extend (rather than replace) parent metadata
if (!event) {
return {
title: "Flockstr Event",
openGraph: {
images: previousImages,
},
};
}
2024-01-11 15:47:19 +00:00
2024-04-27 13:28:53 -04:00
const title = `${getTagValues("title", event.tags as string[][])} | Flockstr`;
2024-01-11 15:47:19 +00:00
const images =
getTagValues("image", event.tags as string[][]) ??
getTagValues("banner", event.tags as string[][]) ??
"";
2023-11-01 12:10:52 -04:00
return {
title: title,
2024-01-11 15:47:19 +00:00
description: event.content,
2023-11-01 12:10:52 -04:00
openGraph: {
title: title,
2024-01-11 15:47:19 +00:00
description: event.content,
images: [images],
2023-11-01 12:10:52 -04:00
},
twitter: {
title: title,
2024-01-11 15:47:19 +00:00
description: event.content,
images: [images],
2023-11-01 12:10:52 -04:00
card: "summary_large_image",
},
};
}
export default function metadataLayout({
children,
}: {
children: React.ReactNode;
}) {
2023-11-01 12:28:53 -04:00
return <>{children}</>;
2023-11-01 12:10:52 -04:00
}