feat: add url shortner
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { resolveShortLink } from "@/lib/share";
|
||||
import { buildShareOgMeta } from "@/lib/share-og";
|
||||
import { ogDefault } from "@/lib/og";
|
||||
import { RedirectClient } from "./redirect-client";
|
||||
|
||||
type PageProps = { params: Promise<{ code: string }> };
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: PageProps): Promise<Metadata> {
|
||||
const { code } = await params;
|
||||
const fullPath = await resolveShortLink(code);
|
||||
if (!fullPath) {
|
||||
return {
|
||||
title: "Link expired — Prabhupāda Says",
|
||||
robots: { index: false, follow: false },
|
||||
...ogDefault(),
|
||||
};
|
||||
}
|
||||
return buildShareOgMeta(fullPath);
|
||||
}
|
||||
|
||||
export default async function SharePage({ params }: PageProps) {
|
||||
const { code } = await params;
|
||||
const fullPath = await resolveShortLink(code);
|
||||
if (!fullPath) notFound();
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex min-h-[60vh] max-w-xl flex-col items-center justify-center px-4 py-16 text-center">
|
||||
<p className="text-muted-foreground text-sm">
|
||||
Redirecting to your highlight…
|
||||
</p>
|
||||
<noscript>
|
||||
<p className="mt-4 text-sm">
|
||||
JavaScript is disabled.{" "}
|
||||
<a className="underline" href={fullPath}>
|
||||
Continue to the page
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
</noscript>
|
||||
<RedirectClient to={fullPath} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user