improving meta tags
This commit is contained in:
parent
3fa54dea99
commit
753210b6b2
@ -1,18 +1,31 @@
|
||||
import type { Metadata, ResolvingMetadata } from "next";
|
||||
import { get } from "@/lib/server-actions/events/cache";
|
||||
import { getEvent } from "@/lib/server-actions/meta/event";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { getTagValues } from "@/lib/nostr/utils";
|
||||
|
||||
export async function generateMetadata(
|
||||
{ params }: { params: { naddr: string } },
|
||||
parent: ResolvingMetadata,
|
||||
): Promise<Metadata> {
|
||||
const previousImages = (await parent).openGraph?.images || [];
|
||||
|
||||
// read route params
|
||||
const identifier = params.naddr;
|
||||
const { data, type } = nip19.decode(identifier);
|
||||
if (type !== "naddr") {
|
||||
return {
|
||||
title: "Flockstr Calendar",
|
||||
openGraph: {
|
||||
images: previousImages,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// fetch data
|
||||
const event = await get(identifier);
|
||||
const event = await getEvent(data.kind, data.pubkey, data.identifier);
|
||||
|
||||
// optionally access and extend (rather than replace) parent metadata
|
||||
const previousImages = (await parent).openGraph?.images || [];
|
||||
if (!event) {
|
||||
return {
|
||||
title: "Flockstr Calendar",
|
||||
@ -21,21 +34,24 @@ export async function generateMetadata(
|
||||
},
|
||||
};
|
||||
}
|
||||
const title = `${event.name} | Flockstr`;
|
||||
const images = event.image
|
||||
? [event.image, ...previousImages]
|
||||
: previousImages;
|
||||
|
||||
const title = `${getTagValues("name", event.tags as string[][])} | Flockstr`;
|
||||
const images =
|
||||
getTagValues("image", event.tags as string[][]) ??
|
||||
getTagValues("banner", event.tags as string[][]) ??
|
||||
"";
|
||||
|
||||
return {
|
||||
title: title,
|
||||
description: event.description,
|
||||
description: event.content,
|
||||
openGraph: {
|
||||
title: title,
|
||||
description: event.description,
|
||||
description: event.content,
|
||||
images: images,
|
||||
},
|
||||
twitter: {
|
||||
title: title,
|
||||
description: event.description,
|
||||
description: event.content,
|
||||
images: images,
|
||||
card: "summary_large_image",
|
||||
},
|
||||
|
@ -1,18 +1,29 @@
|
||||
import type { Metadata, ResolvingMetadata } from "next";
|
||||
import { get } from "@/lib/server-actions/events/cache";
|
||||
import { getEvent } from "@/lib/server-actions/meta/event";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { getTagValues } from "@/lib/nostr/utils";
|
||||
|
||||
export async function generateMetadata(
|
||||
{ params }: { params: { naddr: string } },
|
||||
parent: ResolvingMetadata,
|
||||
): Promise<Metadata> {
|
||||
const previousImages = (await parent).openGraph?.images || [];
|
||||
// read route params
|
||||
const identifier = params.naddr;
|
||||
const { data, type } = nip19.decode(identifier);
|
||||
if (type !== "naddr") {
|
||||
return {
|
||||
title: "Flockstr Event",
|
||||
openGraph: {
|
||||
images: previousImages,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// fetch data
|
||||
const event = await get(identifier);
|
||||
const event = await getEvent(data.kind, data.pubkey, data.identifier);
|
||||
|
||||
// optionally access and extend (rather than replace) parent metadata
|
||||
const previousImages = (await parent).openGraph?.images || [];
|
||||
if (!event) {
|
||||
return {
|
||||
title: "Flockstr Event",
|
||||
@ -21,22 +32,25 @@ export async function generateMetadata(
|
||||
},
|
||||
};
|
||||
}
|
||||
const title = `${event.name} | Flockstr`;
|
||||
const images = event.image
|
||||
? [event.image, ...previousImages]
|
||||
: previousImages;
|
||||
|
||||
const title = `${getTagValues("name", event.tags as string[][])} | Flockstr`;
|
||||
const images =
|
||||
getTagValues("image", event.tags as string[][]) ??
|
||||
getTagValues("banner", event.tags as string[][]) ??
|
||||
"";
|
||||
|
||||
return {
|
||||
title: title,
|
||||
description: event.description,
|
||||
description: event.content,
|
||||
openGraph: {
|
||||
title: title,
|
||||
description: event.description,
|
||||
images: images,
|
||||
description: event.content,
|
||||
images: [images],
|
||||
},
|
||||
twitter: {
|
||||
title: title,
|
||||
description: event.description,
|
||||
images: images,
|
||||
description: event.content,
|
||||
images: [images],
|
||||
card: "summary_large_image",
|
||||
},
|
||||
};
|
||||
|
@ -57,7 +57,7 @@ export default function CreateCalendarEventModal() {
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
setError("Please add a title");
|
||||
setError("Please add a name");
|
||||
return;
|
||||
}
|
||||
setIsLoading(true);
|
||||
|
11
db/client.ts
Normal file
11
db/client.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
declare global {
|
||||
var prisma: PrismaClient | undefined;
|
||||
}
|
||||
|
||||
const prisma = global.prisma || new PrismaClient();
|
||||
|
||||
if (process.env.NODE_ENV === "development") global.prisma = prisma;
|
||||
|
||||
export default prisma;
|
12
lib/server-actions/meta/event.ts
Normal file
12
lib/server-actions/meta/event.ts
Normal file
@ -0,0 +1,12 @@
|
||||
"use server";
|
||||
import prisma from "@/db/client";
|
||||
|
||||
export async function getEvent(kind: number, pubkey: string, d: string) {
|
||||
return await prisma.nostrEvent.findFirst({
|
||||
where: {
|
||||
kind,
|
||||
pubkey,
|
||||
d,
|
||||
},
|
||||
});
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
"@nostr-dev-kit/ndk": "^2.0.0",
|
||||
"@nostr-dev-kit/ndk-cache-dexie": "^2.0.3",
|
||||
"@nostr-dev-kit/ndk-react": "^0.1.1",
|
||||
"@prisma/client": "^5.8.0",
|
||||
"@radix-ui/react-aspect-ratio": "^1.0.3",
|
||||
"@radix-ui/react-avatar": "^1.0.4",
|
||||
"@radix-ui/react-dialog": "^1.0.5",
|
||||
@ -53,6 +54,7 @@
|
||||
"next-themes": "^0.2.1",
|
||||
"node-html-parser": "^6.1.10",
|
||||
"nostr-tools": "^1.16.0",
|
||||
"prisma": "^5.8.0",
|
||||
"ramda": "^0.29.1",
|
||||
"react": "^18",
|
||||
"react-aria": "^3.29.1",
|
||||
|
33
prisma/schema.prisma
Normal file
33
prisma/schema.prisma
Normal file
@ -0,0 +1,33 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
// datasource db {
|
||||
// provider = "postgresql"
|
||||
// url = env("POSTGRES_PRISMA_URL") // uses connection pooling
|
||||
// directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
|
||||
// }
|
||||
|
||||
// generator client {
|
||||
// provider = "prisma-client-js"
|
||||
// }
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_URL")
|
||||
relationMode = "prisma"
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
model NostrEvent {
|
||||
key Int @id @default(autoincrement())
|
||||
id String
|
||||
kind Int
|
||||
content String @default("") @db.Text
|
||||
created_at Int
|
||||
pubkey String
|
||||
tags Json @default("[]")
|
||||
sig String
|
||||
d String?
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user