UNPKG

@paroicms/server

Version:
30 lines 1.6 kB
import { toAbsoluteUrl } from "@paroicms/internal-server-lib"; import { isObj } from "@paroicms/public-anywhere-lib"; import { escapeHtml } from "@paroicms/public-server-lib"; export function injectOpenGraphTagsLiquidFilter(values, { renderingContext }) { if (!isObj(values)) return ""; return generateOpenGraphTags(renderingContext, values); } export async function generateOpenGraphTags(renderingContext, { description, title, image, url, type, siteName, locale }) { const { siteContext } = renderingContext; const tags = []; if (url) tags.push(`<meta property="og:url" content="${escapeHtml(url)}">`); if (locale) tags.push(`<meta property="og:locale" content="${escapeHtml(locale)}">`); if (siteName) tags.push(`<meta property="og:site_name" content="${escapeHtml(siteName)}">`); if (title) tags.push(`<meta property="og:title" content="${escapeHtml(title)}">`); if (type) tags.push(`<meta property="og:type" content="${escapeHtml(type)}">`); if (image) { tags.push(`<meta property="og:image" content="${escapeHtml(toAbsoluteUrl(siteContext, image.url))}">`, `<meta property="og:image:width" content="${image.rawWidth}">`, `<meta property="og:image:height" content="${image.rawHeight}">`, `<meta property="og:image:type" content="${escapeHtml(image.mediaType)}">`); } if (description) { tags.push(`<meta property="og:description" content="${escapeHtml(description)}">`); } return tags.length === 0 ? "" : `${tags.join("\n")}\n`; } //# sourceMappingURL=open-graph-filter.js.map