Place CMS meta tag HTML in the document head.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-10-03 18:46:23 +03:30
co-authored by Cursor
parent b4d6b30243
commit 9bf26705da
3 changed files with 31 additions and 25 deletions
+17 -12
View File
@@ -27,11 +27,26 @@ export async function getBusinessId() {
return tenant?.id != null ? String(tenant.id) : "";
}
/** Full sanitized `<meta …>` HTML from business-info. */
export type BusinessMetaTag = {
name: string;
content: string;
html: string;
};
/** Parse a single `<meta …>` tag into React attribute props for the document head. */
export function parseMetaTagHtml(html: string): Record<string, string> | null {
const match = html.trim().match(/^<meta\b([^>]*)\/?\s*>$/i);
if (!match) return null;
const attrs: Record<string, string> = {};
const attrRe = /([:\w.-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
let found: RegExpExecArray | null;
while ((found = attrRe.exec(match[1]))) {
const key = found[1].toLowerCase();
if (key === "/") continue;
attrs[key] = found[2] ?? found[3] ?? found[4] ?? "";
}
return Object.keys(attrs).length > 0 ? attrs : null;
}
export type BusinessTrustBadge = {
kind: "enamad" | "samandehi";
embedHtml: string;
@@ -45,13 +60,3 @@ export type BusinessInfo = {
export async function getBusinessInfo() {
return meshkeeGet<BusinessInfo | null>(tenantPath("/website/business-info"), null);
}
export function metaTagsToOther(tags: BusinessMetaTag[] | undefined) {
const other: Record<string, string> = {};
for (const tag of tags ?? []) {
const name = tag.name?.trim();
const content = tag.content?.trim();
if (name && content) other[name] = content;
}
return Object.keys(other).length > 0 ? other : undefined;
}