@antora/page-composer
Advanced tools
Comparing version 2.3.4 to 3.0.0-alpha.1
'use strict' | ||
const { posix: path } = require('path') | ||
const { URL } = require('url') | ||
@@ -53,2 +52,3 @@ const { DEFAULT_LAYOUT_NAME } = require('./constants') | ||
model.components = contentCatalog.getComponentsSortedBy('title').reduce((map, it) => (map[it.name] = it) && map, {}) | ||
// NOTE: duplicate site.keys since original is frozen | ||
model.keys = Object.assign({}, playbook.site.keys) | ||
@@ -82,3 +82,3 @@ | ||
// QUESTION can we cache versions on file.rel so only computed once per page version lineage? | ||
const versions = component.versions.length > 1 ? getPageVersions(src, component, contentCatalog) : undefined | ||
const versions = component.versions.length > 1 ? getPageVersions(file, component, contentCatalog) : undefined | ||
const title = file.title || asciidoc.doctitle | ||
@@ -91,2 +91,3 @@ | ||
url, | ||
author: attributes.author, | ||
description: attributes.description, | ||
@@ -141,14 +142,85 @@ keywords: attributes.keywords, | ||
// QUESTION should this function go in ContentCatalog? | ||
// QUESTION should this function accept component, module, relative instead of pageSrc? | ||
function getPageVersions (pageSrc, component, contentCatalog) { | ||
const basePageId = { component: component.name, module: pageSrc.module, family: 'page', relative: pageSrc.relative } | ||
return component.versions.map((componentVersion) => { | ||
const page = contentCatalog.getById(Object.assign({ version: componentVersion.version }, basePageId)) | ||
// QUESTION should title be title of component or page? | ||
return Object.assign( | ||
componentVersion === component.latest ? { latest: true } : {}, | ||
componentVersion, | ||
page ? { url: page.pub.url } : { missing: true } | ||
function getPageVersions (page, component, contentCatalog) { | ||
let basePageId = page.src | ||
const componentVersions = component.versions | ||
const pageVersion = basePageId.version | ||
const thisVersionIdx = componentVersions.findIndex(({ version }) => version === pageVersion) | ||
const thisVersion = componentVersions[thisVersionIdx] | ||
const newerVersions = componentVersions.slice(0, thisVersionIdx) | ||
const olderVersions = componentVersions.slice(thisVersionIdx + 1) | ||
const latestVersion = component.latest | ||
let pageVersions = newerVersions | ||
.reverse() | ||
.reduce((accum, componentVersion) => { | ||
let relPage | ||
const relPageId = Object.assign({}, basePageId, { version: componentVersion.version }) | ||
if ( | ||
!(relPage = contentCatalog.getById(relPageId)) && | ||
(relPage = (contentCatalog.getById((relPageId.family = 'alias') && relPageId) || {}).rel) | ||
) { | ||
// NOTE: don't follow alias that falls outside of component version | ||
if (relPage.src.version === relPageId.version && relPage.src.component === relPageId.component) { | ||
// NOTE: keep searching from target of alias | ||
basePageId = relPage.src | ||
} else { | ||
// QUESTION: should we mark the page as missing or link outside the component version? | ||
//relPage = undefined | ||
} | ||
} | ||
accum.push( | ||
Object.assign( | ||
componentVersion === latestVersion ? { latest: true } : {}, | ||
componentVersion, | ||
relPage ? { url: relPage.pub.url } : { missing: true } | ||
) | ||
) | ||
return accum | ||
}, []) | ||
.reverse() | ||
pageVersions.push( | ||
Object.assign(thisVersion === latestVersion ? { latest: true } : {}, thisVersion, { url: page.pub.url }) | ||
) | ||
basePageId = page.src | ||
let prevPage = page | ||
pageVersions = olderVersions.reduce((accum, componentVersion) => { | ||
let relPage | ||
let primaryAliasSrc | ||
const relPageId = Object.assign({}, basePageId, { version: componentVersion.version }) | ||
if ((relPage = contentCatalog.getById(relPageId))) { | ||
prevPage = relPage | ||
} else if ( | ||
prevPage && | ||
(primaryAliasSrc = (prevPage.rel || {}).src) && | ||
// NOTE: if alias is located in different component or version, it doesn't give us any useful information | ||
primaryAliasSrc.version === prevPage.src.version && | ||
primaryAliasSrc.component === prevPage.src.component | ||
) { | ||
relPageId.module = primaryAliasSrc.module | ||
relPageId.relative = primaryAliasSrc.relative | ||
if ((relPage = contentCatalog.getById(relPageId))) { | ||
// NOTE: keep searching from target of alias | ||
basePageId = (prevPage = relPage).src | ||
} else if ((relPage = (contentCatalog.getById((relPageId.family = 'alias') && relPageId) || {}).rel)) { | ||
// NOTE: don't follow alias that falls outside of component version | ||
if (relPage.src.version === relPageId.version && relPage.src.component === relPageId.component) { | ||
// NOTE: keep searching from target of alias | ||
basePageId = (prevPage = relPage).src | ||
} else { | ||
// QUESTION: should we update version on prevPage so older versions can continue to follow it? | ||
prevPage = undefined | ||
// QUESTION: should we mark the page as missing or link outside the component version? | ||
//relPage = undefined | ||
} | ||
} | ||
} | ||
accum.push( | ||
Object.assign( | ||
componentVersion === latestVersion ? { latest: true } : {}, | ||
componentVersion, | ||
relPage ? { url: relPage.pub.url } : { missing: true } | ||
) | ||
) | ||
}) | ||
return accum | ||
}, pageVersions) | ||
return pageVersions | ||
} | ||
@@ -162,3 +234,3 @@ | ||
// QUESTION should we filter out component start page from the breadcrumbs? | ||
const breadcrumbs = ancestors.filter((item) => 'content' in item) | ||
const breadcrumbs = ancestors.filter((item) => 'content' in item).reverse() | ||
const parent = breadcrumbs.find((item) => item.urlType === 'internal') | ||
@@ -204,3 +276,3 @@ breadcrumbs.reverse().push(match) | ||
correlated = findNavItem( | ||
correlated.match ? correlated : Object.assign({}, correlated, { ancestors: [candidate].concat(ancestors) }), | ||
correlated.match ? correlated : Object.assign({}, correlated, { ancestors: [...ancestors, candidate] }), | ||
children, | ||
@@ -207,0 +279,0 @@ false |
@@ -85,4 +85,4 @@ 'use strict' | ||
file.contents = Buffer.from(layouts.get(layout)(uiModel)) | ||
} catch (e) { | ||
throw transformHandlebarsError(e, layout) | ||
} catch (err) { | ||
throw transformHandlebarsError(err, layout) | ||
} | ||
@@ -97,3 +97,3 @@ return file | ||
const err = new Error(`${message}${~message.indexOf('\n') ? '\n^ ' : ' '}in UI template ${templatePath}`) | ||
err.stack = [err.toString()].concat(stack.substr(message.length + 8)).join('\n') | ||
err.stack = [err.toString(), stack.substr(message.length + 8)].join('\n') | ||
return err | ||
@@ -100,0 +100,0 @@ } |
@@ -7,3 +7,3 @@ 'use strict' | ||
if (page.component) { | ||
context = { component: page.component.name, version: page.version, module: page.module, ...context } | ||
context = Object.assign({ component: page.component.name, version: page.version, module: page.module }, context) | ||
} | ||
@@ -10,0 +10,0 @@ const file = contentCatalog.resolvePage(spec, context) |
@@ -10,3 +10,3 @@ 'use strict' | ||
if (page.component) { | ||
context = { component: page.component.name, version: page.version, module: page.module, ...context } | ||
context = Object.assign({ component: page.component.name, version: page.version, module: page.module }, context) | ||
} | ||
@@ -13,0 +13,0 @@ const file = contentCatalog.resolvePage(spec, context) |
{ | ||
"name": "@antora/page-composer", | ||
"version": "2.3.4", | ||
"version": "3.0.0-alpha.1", | ||
"description": "Wraps the embeddable HTML contents of each page file from the content catalog in a page layout to yield standalone pages in an Antora documentation pipeline.", | ||
@@ -22,3 +22,3 @@ "license": "MPL-2.0", | ||
"engines": { | ||
"node": ">=8.11.0" | ||
"node": ">=10.17.0" | ||
}, | ||
@@ -37,3 +37,3 @@ "files": [ | ||
], | ||
"gitHead": "5a40191c970ece6baecbd1a3a7a599d7161351a9" | ||
"gitHead": "337ff6d2ed11e1f4d0a8ef993ddc8eaac7a73e9f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36251
421
1