UNPKG

@becklyn/contentful-adapter

Version:

[![CI](https://github.com/Becklyn-Studios/contentful-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/Becklyn-Studios/contentful-adapter/actions/workflows/ci.yml)

58 lines (57 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLabeledLinkFromContentful = exports.getAssetFromContentful = exports.getContentfulWhereObject = exports.getContentfulSelectString = void 0; const getContentfulSelectString = (select) => { if (!select) { return null; } if (!select.includes("sys.id")) { select.unshift("sys.id"); } return select.join(","); }; exports.getContentfulSelectString = getContentfulSelectString; const getContentfulWhereObject = (where) => { return !!where ? where : {}; }; exports.getContentfulWhereObject = getContentfulWhereObject; const getAssetFromContentful = (data) => { var _a, _b; if (!data) { return null; } return { url: data.fields.file.url, contentType: data.fields.file.contentType, title: data.fields.title, height: (_a = data.fields.file.details.image) === null || _a === void 0 ? void 0 : _a.height, width: (_b = data.fields.file.details.image) === null || _b === void 0 ? void 0 : _b.width, }; }; exports.getAssetFromContentful = getAssetFromContentful; const getLabeledLinkFromContentful = async (pageCache, data, pageContentType = "page") => { var _a, _b; if (!data) { return null; } const ref = data.fields.reference; let reference = { url: "", inNewTab: false, }; if (ref.sys.contentType.sys.id === pageContentType) { reference.url = pageCache.getSlugOfPage(ref.sys.id); } else if (ref.sys.contentType.sys.id === "externalReference" && ref.fields.url) { reference.url = ref.fields.url; reference.inNewTab = (_a = ref.fields.inNewTab) !== null && _a !== void 0 ? _a : false; } else { reference = null; } return { label: (_b = data.fields.label) !== null && _b !== void 0 ? _b : null, reference, }; }; exports.getLabeledLinkFromContentful = getLabeledLinkFromContentful;