mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
feat: generate metatags for share page with og image
This commit is contained in:
48
apps/web/src/app/(share)/share/[shareId]/page.tsx
Normal file
48
apps/web/src/app/(share)/share/[shareId]/page.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import { getSharingId } from '@documenso/lib/server-only/share/get-share-id';
|
||||
|
||||
type MetadataProps = {
|
||||
params: { shareId: string };
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params }: MetadataProps): Promise<Metadata> {
|
||||
const id = params.shareId;
|
||||
const share = await getSharingId({ shareId: id });
|
||||
const signature = share?.recipent.name || share?.recipent.email;
|
||||
|
||||
return {
|
||||
title: 'Documenso - Share',
|
||||
openGraph: {
|
||||
images: [`/api/share-og?signature=${signature}`],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type SharePageProps = {
|
||||
params: {
|
||||
shareId?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export default async function SharePage({ params: { shareId } }: SharePageProps) {
|
||||
if (!shareId) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const share = await getSharingId({ shareId });
|
||||
|
||||
if (!share) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-screen flex-col items-center justify-center">
|
||||
<h1 className="my-2 text-4xl font-semibold">Share Page</h1>
|
||||
<p className="my-2 text-xl">Redirecting...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
export type SharePageProps = {
|
||||
params: {
|
||||
shortId?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export default async function SharePage({ params: { shortId } }: SharePageProps) {
|
||||
console.log(shortId);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Share Page</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
18
packages/lib/server-only/share/get-share-id.ts
Normal file
18
packages/lib/server-only/share/get-share-id.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export interface GetSharingIdOptions {
|
||||
shareId: string;
|
||||
}
|
||||
|
||||
export const getSharingId = async ({ shareId }: GetSharingIdOptions) => {
|
||||
const result = await prisma.share.findUnique({
|
||||
where: {
|
||||
link: shareId,
|
||||
},
|
||||
include: {
|
||||
recipent: true,
|
||||
},
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
Reference in New Issue
Block a user