UNPKG

arc-xp-custom-blocks

Version:

arc libraries for ingala

125 lines (124 loc) 4.25 kB
import generateResizedImageUrl from "./generateResizedImageUrl.js"; function tagPageMetaDataGenerator(fusionContext = {}, metaValue = () => { }) { var _a, _b, _c, _d, _e, _f, _g, _h; const { globalContent = {}, requestUri, siteProperties = {} } = fusionContext; const { description, fallbackImageAlt, fallbackImageAuth, fallbackImageFocalPoint, fallbackImageUrl, keywords, metaData = { ogImageWidth: 1200, ogImageHeight: 630 }, resizerTokenVersion = "1", resizerURL, twitterUsername, websiteDomain, websiteName } = siteProperties; const { ogImageWidth, ogImageHeight, twitterCard } = metaData; const payload = (_b = (_a = globalContent == null ? void 0 : globalContent.Payload) == null ? void 0 : _a[0]) != null ? _b : {}; const payloadDescription = payload == null ? void 0 : payload.description; const payloadName = payload == null ? void 0 : payload.name; const config = { resizerTokenVersion, resizerURL }; const fallbackPromoItem = { url: fallbackImageUrl, auth: { [resizerTokenVersion]: fallbackImageAuth }, focal_point: fallbackImageFocalPoint }; const imageUrl = generateResizedImageUrl(fallbackPromoItem, config, ogImageWidth, ogImageHeight); const robots = ((_c = metaValue("robots")) == null ? void 0 : _c.trim()) || ((_d = siteProperties == null ? void 0 : siteProperties.robots) == null ? void 0 : _d.trim()); const tagDescription = ((_e = metaValue("description")) == null ? void 0 : _e.trim()) || (payloadDescription == null ? void 0 : payloadDescription.trim()) || description; const tagKeywords = ((_f = metaValue("keywords")) == null ? void 0 : _f.trim()) || (keywords == null ? void 0 : keywords.trim()); const title = ((_g = metaValue("title")) == null ? void 0 : _g.trim()) || (payloadName == null ? void 0 : payloadName.trim()); const titleSufix = (_h = metaValue("title-sufix")) == null ? void 0 : _h.trim(); const tagTitle = title && titleSufix && `${title} - ${titleSufix}` || title || (websiteName == null ? void 0 : websiteName.trim()); const url = requestUri && `${websiteDomain}${requestUri}` || websiteDomain; const metadata = {}; const metadataProperties = { "robots": robots && { name: "robots", content: robots }, "og:site_name": websiteName && { property: "og:site_name", content: websiteName }, "og:type": { property: "og:type", content: "website" }, "og:url": url && { name: "og:url", content: url }, "description": tagDescription && { name: "description", content: tagDescription }, "og:description": tagDescription && { property: "og:description", content: tagDescription }, "twitter:description": tagDescription && { name: "twitter:description", content: tagDescription }, "og:title": tagTitle && { property: "og:title", content: tagTitle }, "twitter:title": tagTitle && { name: "twitter:title", content: tagTitle }, "author": websiteName && { name: "author", content: websiteName }, "keywords": tagKeywords && { name: "keywords", content: tagKeywords }, "og:image": imageUrl && { property: "og:image", content: imageUrl }, "twitter:image": imageUrl && { name: "twitter:image", content: imageUrl }, "og:image:alt": fallbackImageAlt && { property: "og:image:alt", content: fallbackImageAlt }, "twitter:image:alt": fallbackImageAlt && { name: "twitter:image:alt", content: fallbackImageAlt }, "og:image:width": imageUrl && { property: "og:image:width", content: ogImageWidth }, "og:image:height": imageUrl && { property: "og:image:height", content: ogImageHeight }, "twitter:card": twitterCard && { name: "twitter:card", content: twitterCard }, "twitter:site": twitterUsername && { name: "twitter:site", content: `@${twitterUsername}` } }; Object.entries(metadataProperties).forEach(([key, value]) => { value ? metadata[key] = value : null; }); return metadata; } export { tagPageMetaDataGenerator as default };