UNPKG

bidasoa-components

Version:

Colección de componentes comunes empleados en proyectos Bidasoa.

118 lines (117 loc) 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBreadcrumbs = exports.hasBreadcrumbs = exports.getId = exports.getParagraphs = exports.hasParagraphs = exports.getSubtitle = exports.hasSubtitle = exports.getNodeTitle = exports.getLinkMetatags = exports.getContentMetaTags = exports.getPageTitle = exports.isNodeToBuild = exports.getNodeLangcode = exports.getNodeTranslations = void 0; function getNodeTranslations(node) { return node.data.content.translations; } exports.getNodeTranslations = getNodeTranslations; function getNodeLangcode(node) { return node.data.content.language.id; } exports.getNodeLangcode = getNodeLangcode; function isNodeToBuild(node) { var _a; return node.data.content.isPublished && Boolean((_a = node.data.content.url) === null || _a === void 0 ? void 0 : _a.path); } exports.isNodeToBuild = isNodeToBuild; function getPageTitle(nodeDto) { const content = nodeDto.data.content; if (!(content === null || content === void 0 ? void 0 : content.metas)) { return content === null || content === void 0 ? void 0 : content.title; } const metaTitle = content.metas.find((meta) => meta.type === 'MetaValue' && meta.property === 'title'); if (!metaTitle) { return content.title; } return metaTitle.content; } exports.getPageTitle = getPageTitle; function getContentMetaTags(nodeDto) { const content = nodeDto.data.content; if (!(content === null || content === void 0 ? void 0 : content.metas)) { return undefined; } return content.metas .filter((meta) => meta.type === 'MetaValue' || meta.type === 'MetaProperty' || meta.type === 'MetaHttpEquiv' || meta.type === 'MetaItemProp') .filter((meta) => meta.property !== 'title') .map((meta) => { if (meta.type === 'MetaProperty') { return { property: meta.property, content: meta.content, }; } if (meta.type === 'MetaHttpEquiv') { return { 'http-equiv': meta.property, 'content': meta.content, }; } if (meta.type === 'MetaItemProp') { return { itemprop: meta.property, content: meta.content, }; } return { name: meta.property, content: meta.content }; }); } exports.getContentMetaTags = getContentMetaTags; function getLinkMetatags(node) { const content = node.data.content; if (!(content === null || content === void 0 ? void 0 : content.metas)) { return undefined; } return content.metas .filter((meta) => meta.type === 'MetaLink' || meta.type === 'MetaLinkHreflang') .map((meta) => { if (meta.type === 'MetaLinkHreflang' || meta.property === 'alternate') { const { content } = meta; return Object.assign({}, content); } return { rel: meta.property, href: meta.content }; }); } exports.getLinkMetatags = getLinkMetatags; function getNodeTitle(node) { return node.data.content.title; } exports.getNodeTitle = getNodeTitle; function hasSubtitle(node) { return Boolean(node.data.content.subtitle); } exports.hasSubtitle = hasSubtitle; function getSubtitle(node) { return node.data.content.subtitle; } exports.getSubtitle = getSubtitle; function hasParagraphs(node) { return Boolean(node.data.content.paragraphs); } exports.hasParagraphs = hasParagraphs; function getParagraphs(node) { if (!node.data.content.paragraphs) { return []; } return node.data.content.paragraphs; } exports.getParagraphs = getParagraphs; function getId(node) { return node.data.content.id; } exports.getId = getId; function hasBreadcrumbs(node) { var _a; return !!node.data.content.url.breadcumbs && ((_a = node.data.content.url.breadcumbs) === null || _a === void 0 ? void 0 : _a.length) > 0; } exports.hasBreadcrumbs = hasBreadcrumbs; function getBreadcrumbs(node) { if (!node.data.content.url.breadcumbs) { return []; } return node.data.content.url.breadcumbs; } exports.getBreadcrumbs = getBreadcrumbs;