Persian RTL clinic site with Meshkee blog, auth, sitemap config, and on-page SEO. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import type { Metadata } from "next";
|
|
|
|
import { site } from "@/data/site";
|
|
import { websiteDomain } from "@/lib/config";
|
|
|
|
export const siteUrl = `https://${websiteDomain}`;
|
|
|
|
export function clipMetaDescription(text: string, max = 158) {
|
|
const clean = text.replace(/\s+/g, " ").trim();
|
|
if (clean.length <= max) return clean;
|
|
const cut = clean.slice(0, max - 1);
|
|
const lastSpace = cut.lastIndexOf(" ");
|
|
return `${(lastSpace > 80 ? cut.slice(0, lastSpace) : cut).trim()}…`;
|
|
}
|
|
|
|
export function pageTitle(title: string, path = "/") {
|
|
if (path === "/" || title.includes(site.doctorName) || title.includes(site.name)) {
|
|
return title;
|
|
}
|
|
return `${title} | ${site.doctorName}`;
|
|
}
|
|
|
|
export function pageMetadata({
|
|
title,
|
|
description,
|
|
path = "/",
|
|
image,
|
|
}: {
|
|
title: string;
|
|
description: string;
|
|
path?: string;
|
|
image?: string | null;
|
|
}): Metadata {
|
|
const url = `${siteUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
const fullTitle = pageTitle(title, path);
|
|
const metaDescription = clipMetaDescription(description);
|
|
const ogImage = image || `${siteUrl}/images/logo.png`;
|
|
const isDetail = path.split("/").filter(Boolean).length > 1;
|
|
|
|
return {
|
|
title: { absolute: fullTitle },
|
|
description: metaDescription,
|
|
robots: { index: true, follow: true },
|
|
alternates: { canonical: url },
|
|
openGraph: {
|
|
type: isDetail ? "article" : "website",
|
|
locale: "fa_IR",
|
|
url,
|
|
siteName: site.name,
|
|
title: fullTitle,
|
|
description: metaDescription,
|
|
images: [{ url: ogImage, alt: fullTitle }],
|
|
},
|
|
twitter: {
|
|
card: "summary_large_image",
|
|
title: fullTitle,
|
|
description: metaDescription,
|
|
images: [ogImage],
|
|
},
|
|
};
|
|
}
|