UNPKG

arc-xp-custom-blocks

Version:

arc libraries for ingala

120 lines (119 loc) 3.58 kB
import generateResizedImageUrl from "./generateResizedImageUrl.js"; function homePageMetaDataGenerator(fusionContext = {}, metaValue = () => { }) { var _a, _b, _c, _d, _e; const { 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 config = { resizerTokenVersion, resizerURL }; const promoItem = { url: fallbackImageUrl, auth: { [resizerTokenVersion]: fallbackImageAuth }, focal_point: fallbackImageFocalPoint }; const homeDescription = ((_a = metaValue("description")) == null ? void 0 : _a.trim()) || description; const homeKeywords = ((_b = metaValue("keywords")) == null ? void 0 : _b.trim()) || (keywords == null ? void 0 : keywords.trim()); const homeTitle = ((_c = metaValue("title")) == null ? void 0 : _c.trim()) || websiteName; const imageUrl = generateResizedImageUrl(promoItem, 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 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": websiteDomain && { name: "og:url", content: websiteDomain }, "description": homeDescription && { name: "description", content: homeDescription }, "og:description": homeDescription && { property: "og:description", content: homeDescription }, "twitter:description": homeDescription && { name: "twitter:description", content: homeDescription }, "og:title": homeTitle && { property: "og:title", content: homeTitle }, "twitter:title": homeTitle && { name: "twitter:title", content: homeTitle }, "author": websiteName && { name: "author", content: websiteName }, "keywords": homeKeywords && { name: "keywords", content: homeKeywords }, // Image "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 && twitterUsername && { 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 { homePageMetaDataGenerator as default };