From 7ea3fe76c99c88a45621a99f9e94d78123ee804f Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Sat, 3 Oct 2026 18:39:21 +0330 Subject: [PATCH] Inject CMS meta tags as full HTML from business-info. metaTags is now { html }; parse into head elements instead of name/content metadata. Co-authored-by: Cursor --- src/app/layout.tsx | 21 +++++++++++++++------ src/lib/meshkee.ts | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b0bfd54..cab20d3 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -6,7 +6,12 @@ import { TopBar } from "@/components/home/TopBar"; import { Header } from "@/components/home/Header"; import { Footer } from "@/components/home/Footer"; import { Providers } from "@/context/Providers"; -import { getBusinessInfo, getCategories, getCategoryTree } from "@/lib/meshkee"; +import { + getBusinessInfo, + getCategories, + getCategoryTree, + parseMetaTagHtml, +} from "@/lib/meshkee"; // Body text — headings use the bold weight instead, see globals.css. const iranyekan = localFont({ @@ -29,16 +34,11 @@ const syne = Syne({ export async function generateMetadata(): Promise { const businessInfo = await getBusinessInfo(); - const other: Record = {}; - for (const tag of businessInfo?.metaTags ?? []) { - if (tag.name && tag.content) other[tag.name] = tag.content; - } return { title: "صنیع هوم | فروشگاه لوازم خانگی", description: "فروشگاه آنلاین لوازم خانگی — یخچال، لباسشویی، تلویزیون و بیشتر", icons: businessInfo?.faviconUrl ? [{ url: businessInfo.faviconUrl }] : undefined, - ...(Object.keys(other).length > 0 ? { other } : {}), }; } @@ -49,12 +49,21 @@ export default async function RootLayout({ children }: LayoutProps<"/">) { getBusinessInfo(), ]); + const cmsMetaTags = (businessInfo?.metaTags ?? []) + .map((tag, index) => { + const attrs = parseMetaTagHtml(tag.html ?? ""); + if (!attrs) return null; + return ; + }) + .filter(Boolean); + return ( + {cmsMetaTags.length > 0 ? {cmsMetaTags} : null} diff --git a/src/lib/meshkee.ts b/src/lib/meshkee.ts index d1e4264..37e06cf 100644 --- a/src/lib/meshkee.ts +++ b/src/lib/meshkee.ts @@ -44,11 +44,26 @@ async function apiPost( } } +/** Full sanitized `` HTML from business-info. */ export type BusinessMetaTag = { - name: string; - content: string; + html: string; }; +/** Parse a single `` tag into React/Next attribute props. */ +export function parseMetaTagHtml(html: string): Record | null { + const match = html.trim().match(/^]*)\/?\s*>$/i); + if (!match) return null; + const attrs: Record = {}; + const attrRe = /([:\w.-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g; + let m: RegExpExecArray | null; + while ((m = attrRe.exec(match[1]))) { + const key = m[1].toLowerCase(); + if (key === '/') continue; + attrs[key] = m[2] ?? m[3] ?? m[4] ?? ''; + } + return Object.keys(attrs).length > 0 ? attrs : null; +} + export type BusinessTrustBadge = { kind: "enamad" | "samandehi"; embedHtml: string;