UNPKG

arc-xp-custom-blocks

Version:

arc libraries for ingala

125 lines (124 loc) 4.58 kB
import generateResizedImageUrl from "./generateResizedImageUrl.js"; function sectionPageMetaDataGenerator(fusionContext = {}, metaValue = () => { }) { var _a, _b, _c, _d, _e, _f, _g, _h, _i; const { globalContent = {}, requestUri, siteProperties = {} } = fusionContext; const { description: sitePropertiesDescription, fallbackImageAlt, fallbackImageAuth, fallbackImageFocalPoint, fallbackImageUrl, keywords, metaData = { ogImageWidth: 1200, ogImageHeight: 630 }, resizerTokenVersion = "1", resizerURL, twitterUsername, websiteDomain, websiteName } = siteProperties; const { ogImageWidth, ogImageHeight, twitterCard } = metaData; const sectionSiteDescription = (_a = globalContent == null ? void 0 : globalContent.site) == null ? void 0 : _a.site_description; const sectionSiteKeywords = (_b = globalContent == null ? void 0 : globalContent.site) == null ? void 0 : _b.site_keywords; const sectionTitle = (_c = globalContent == null ? void 0 : globalContent.site) == null ? void 0 : _c.site_title; const config = { resizerTokenVersion, resizerURL }; const fallbackPromoItem = { url: fallbackImageUrl, auth: { [resizerTokenVersion]: fallbackImageAuth }, focal_point: fallbackImageFocalPoint }; const imageUrl = generateResizedImageUrl(fallbackPromoItem, config, ogImageWidth, ogImageHeight); const robots = ((_d = metaValue("robots")) == null ? void 0 : _d.trim()) || ((_e = siteProperties == null ? void 0 : siteProperties.robots) == null ? void 0 : _e.trim()); const sectionDescription = ((_f = metaValue("description")) == null ? void 0 : _f.trim()) || (sectionSiteDescription == null ? void 0 : sectionSiteDescription.trim()) || (sitePropertiesDescription == null ? void 0 : sitePropertiesDescription.trim()); const sectionKeywords = ((_g = metaValue("keywords")) == null ? void 0 : _g.trim()) || (sectionSiteKeywords == null ? void 0 : sectionSiteKeywords.trim()) || (keywords == null ? void 0 : keywords.trim()); const title = ((_h = metaValue("title")) == null ? void 0 : _h.trim()) || (sectionTitle == null ? void 0 : sectionTitle.trim()); const titleSufix = (_i = metaValue("title-sufix")) == null ? void 0 : _i.trim(); const tiitleOg = 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": sectionDescription && { name: "description", content: sectionDescription }, "og:description": sectionDescription && { property: "og:description", content: sectionDescription }, "twitter:description": sectionDescription && { name: "twitter:description", content: sectionDescription }, "og:title": tiitleOg && { property: "og:title", content: tiitleOg }, "twitter:title": tiitleOg && { name: "twitter:title", content: tiitleOg }, "author": websiteName && { name: "author", content: websiteName }, "keywords": sectionKeywords && { name: "keywords", content: sectionKeywords }, "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 { sectionPageMetaDataGenerator as default };