@antora/page-composer
Advanced tools
Comparing version 3.0.3 to 3.1.0
'use strict' | ||
const { buildBaseUiModel, buildUiModel } = require('./build-ui-model') | ||
const handlebars = require('handlebars') | ||
const Handlebars = require('handlebars') | ||
const logger = require('./logger') | ||
@@ -29,2 +29,3 @@ const relativize = require('./helpers/relativize') | ||
function createPageComposer (playbook, contentCatalog, uiCatalog) { | ||
const handlebars = Handlebars.create() | ||
handlebars.registerHelper('relativize', relativize) | ||
@@ -39,12 +40,9 @@ handlebars.registerHelper('resolvePage', resolvePage) | ||
uiCatalog.findByType('partial').forEach(({ stem, contents }) => handlebars.registerPartial(stem, contents.toString())) | ||
const layouts = uiCatalog | ||
.findByType('layout') | ||
.reduce( | ||
(accum, { path: srcName, stem, contents }) => | ||
accum.set(stem, handlebars.compile(contents.toString(), { preventIndent: true, srcName })), | ||
new Map() | ||
) | ||
const composePage = createPageComposerInternal(buildBaseUiModel(playbook, contentCatalog), layouts) | ||
const create404Page = (siteAsciiDocConfig) => { | ||
return composePage({ | ||
handlebars.layouts = uiCatalog.findByType('layout').reduce((accum, { path: srcName, stem, contents }) => { | ||
accum[stem] = handlebars.compile(contents.toString(), { preventIndent: true, srcName }) | ||
return accum | ||
}, {}) | ||
const composePage = createPageComposerInternal(handlebars, buildBaseUiModel(playbook, contentCatalog)) | ||
const create404Page = (siteAsciiDocConfig) => | ||
composePage({ | ||
asciidoc: siteAsciiDocConfig, | ||
@@ -57,7 +55,6 @@ mediaType: 'text/html', | ||
}) | ||
} | ||
return Object.assign(composePage, { composePage, create404Page }) | ||
return Object.assign(composePage, { composePage, create404Page, handlebars }) | ||
} | ||
function createPageComposerInternal (baseUiModel, layouts) { | ||
function createPageComposerInternal ({ layouts }, baseUiModel) { | ||
/** | ||
@@ -85,3 +82,3 @@ * Wraps the embeddable HTML contents of the specified file in a page layout. | ||
let layout = uiModel.page.layout | ||
if (!layouts.has(layout)) { | ||
if (!(layout in layouts)) { | ||
if (layout === '404') throw new Error('404 layout not found') | ||
@@ -91,6 +88,10 @@ const defaultLayout = uiModel.site.ui.defaultLayout | ||
throw new Error(`${layout} layout not found`) | ||
} else if (!layouts.has(defaultLayout)) { | ||
} else if (!(defaultLayout in layouts)) { | ||
throw new Error(`Neither ${layout} layout or fallback ${defaultLayout} layout found`) | ||
} | ||
logger.warn({ file: file.src }, "page layout '%s' specified by page not found; using default layout", layout) | ||
logger.warn( | ||
{ file: file.src }, | ||
'Page layout specified by page not found: %s (reverting to default layout)', | ||
layout | ||
) | ||
layout = defaultLayout | ||
@@ -100,3 +101,3 @@ } | ||
try { | ||
file.contents = Buffer.from(layouts.get(layout)(uiModel)) | ||
file.contents = Buffer.from(layouts[layout](uiModel)) | ||
} catch (err) { | ||
@@ -110,3 +111,3 @@ throw transformHandlebarsError(err, layout) | ||
function transformHandlebarsError ({ message, stack }, layout) { | ||
const m = stack.match(/^ *at Object\.ret \[as (.+?)\]/m) | ||
const m = stack.match(/\n *at Object\.ret \[as (.+?)\].*\n *at Object\.invokePartialWrapper \[as invokePartial\]/) | ||
const templatePath = `${m ? 'partials/' + m[1] : 'layouts/' + layout}.hbs` | ||
@@ -113,0 +114,0 @@ const err = new Error(`${message}${~message.indexOf('\n') ? '\n^ ' : ' '}in UI template ${templatePath}`) |
{ | ||
"name": "@antora/page-composer", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"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.", | ||
@@ -17,4 +17,10 @@ "license": "MPL-2.0", | ||
"main": "lib/index.js", | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./build-ui-model": "./lib/build-ui-model.js", | ||
"./lib/build-ui-model": "./lib/build-ui-model.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"dependencies": { | ||
"@antora/logger": "3.0.3", | ||
"@antora/logger": "3.1.0", | ||
"handlebars": "~4.7", | ||
@@ -24,3 +30,3 @@ "require-from-string": "~2.0" | ||
"engines": { | ||
"node": ">=12.21.0" | ||
"node": ">=16.0.0" | ||
}, | ||
@@ -27,0 +33,0 @@ "files": [ |
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
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
20528
437
+ Added@antora/logger@3.1.0(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedfast-copy@2.1.7(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedhelp-me@4.2.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addedon-exit-leak-free@2.1.2(transitive)
+ Addedpino@8.4.2(transitive)
+ Addedpino-pretty@9.0.1(transitive)
+ Addedpino-std-serializers@6.2.2(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedprocess-warning@2.3.2(transitive)
+ Addedreadable-stream@4.5.2(transitive)
+ Addedreal-require@0.2.0(transitive)
+ Addedsonic-boom@3.2.1(transitive)
+ Addedthread-stream@2.7.0(transitive)
- Removed@antora/logger@3.0.3(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedargs@5.0.3(transitive)
- Removedcamelcase@5.0.0(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedleven@2.1.0(transitive)
- Removedmri@1.1.4(transitive)
- Removedon-exit-leak-free@0.2.0(transitive)
- Removedpino@7.6.5(transitive)
- Removedpino-pretty@7.3.0(transitive)
- Removedpino-std-serializers@4.0.0(transitive)
- Removedprocess-warning@1.0.0(transitive)
- Removedreal-require@0.1.0(transitive)
- Removedrfdc@1.4.1(transitive)
- Removedsonic-boom@2.4.2(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedthread-stream@0.13.2(transitive)
Updated@antora/logger@3.1.0