@antora/assembler
Advanced tools
Comparing version 1.0.0-alpha.6 to 1.0.0-alpha.7
@@ -34,3 +34,3 @@ 'use strict' | ||
// TODO: if no workspace dir is defined; we shouldn't continue | ||
// TODO: if no workspace dir is defined, we shouldn't continue | ||
function prepareWorkspace (publishFiles, aggregateDocuments, contentCatalog, buildConfig) { | ||
@@ -37,0 +37,0 @@ const { dir, clean, keepAggregateSource } = buildConfig |
'use strict' | ||
const expandPath = require('@antora/expand-path-helper') | ||
const { promises: fsp } = require('fs') | ||
const os = require('os') | ||
const fsp = require('node:fs/promises') | ||
const os = require('node:os') | ||
const yaml = require('js-yaml') | ||
@@ -30,3 +30,3 @@ | ||
if (!('doctype' in asciidocAttrs)) asciidocAttrs.doctype = 'book' | ||
asciidocAttrs.revdate = new Date().toISOString().split('T')[0] | ||
if (!('revdate' in asciidocAttrs)) asciidocAttrs.revdate = getLocalDate() | ||
asciidocAttrs['page-partial'] = null | ||
@@ -72,2 +72,6 @@ if (config.componentVersions == null) { | ||
function getLocalDate (now = new Date()) { | ||
return new Date(now - now.getTimezoneOffset() * 60000).toISOString().split('T')[0] | ||
} | ||
module.exports = loadConfig |
'use strict' | ||
const File = require('vinyl') | ||
const { posix: path } = require('path') | ||
const path = require('node:path/posix') | ||
@@ -17,3 +17,6 @@ function produceAggregateDocument ( | ||
) { | ||
const pagesInOutline = selectPagesInOutline(outline, pages) | ||
const pagesInOutline = selectPagesInOutline( | ||
outline, | ||
pages.filter((it) => it.out) | ||
) | ||
const navtitle = outline.content | ||
@@ -54,4 +57,5 @@ const stem = generateStem(componentVersion, navtitle) | ||
`= ${doctitle}`, | ||
...(version ? [`v${version}`] : []), | ||
...(version ? [`:revnumber: ${version}`] : []), | ||
...(doctype === 'article' ? [] : [`:doctype: ${doctype}`]), | ||
':underscore: _', | ||
// Q: should we pass these via the CLI so they cannot be modified? | ||
@@ -114,5 +118,4 @@ `:page-component-name: ${componentVersion.name}`, | ||
const docname = doc.getAttribute('docname') | ||
//const idprefix = `${module_ === 'ROOT' ? '' : module_ + ':'}${docname}//` | ||
const idprefix = `${module_ === 'ROOT' ? '' : module_ + ':'}${docname.replace(/[/]/g, '::')}:::` | ||
//const idprefix = `${module_ === 'ROOT' ? '' : module_ + ':'}${docname.replace(/[/]/g, ':-:')}:--:` | ||
const docnameForId = docname.replace(/[/]/g, '::').replace(/[.]/g, '-') | ||
const idprefix = `${module_ === 'ROOT' ? '' : module_ + ':'}${docnameForId}:::` | ||
buffer.push('') | ||
@@ -212,5 +215,19 @@ buffer.push(`:docname: ${docname}`) | ||
}) | ||
let skipping | ||
for (let idx = 0, len = lines.length; idx < len; idx++) { | ||
if (~ignoreLines.indexOf(idx)) continue | ||
let line = lines[idx] | ||
if (line.startsWith('//')) { | ||
if (line[2] !== '/') continue | ||
if (line.length > 3 && line === '/'.repeat(line.length)) { | ||
if (skipping) { | ||
if (line === skipping) skipping = undefined | ||
} else { | ||
skipping = line | ||
} | ||
continue | ||
} | ||
} else if (skipping) { | ||
continue | ||
} | ||
if (line.charAt() === ':' && /^:(?:leveloffset: .*|!leveloffset:|leveloffset!:)$/.test(line)) { | ||
@@ -258,3 +275,3 @@ if (lines[idx - 1] === '') lines[idx - 1] = undefined | ||
// TODO: handle unresolved page better | ||
return siteUrl && (targetPage = contentCatalog.resolvePage(pagePart, page.src)) | ||
return siteUrl && (targetPage = contentCatalog.resolvePage(pagePart, page.src)) && targetPage.out | ||
? `${siteUrl}${targetPage.pub.url}${fragment && '#' + fragment}[${text}]` | ||
@@ -269,7 +286,10 @@ : m | ||
// TODO: handle unresolved page better | ||
return siteUrl && (targetPage = contentCatalog.resolvePage(target, page.src)) | ||
return siteUrl && (targetPage = contentCatalog.resolvePage(target, page.src)) && targetPage.out | ||
? `${siteUrl}${targetPage.pub.url}${fragment && '#' + fragment}[${text}]` | ||
: m | ||
} | ||
pagePart = pagePart.replace(/[/]/g, '::').replace(/\.adoc$/, '') | ||
pagePart = pagePart | ||
.replace(/[/]/g, '::') | ||
.replace(/\.adoc$/, '') | ||
.replace(/[.]/g, '-') | ||
const refid = `${pagePart}:::${fragment}` | ||
@@ -290,3 +310,5 @@ return `<<${refid}${text && text !== targetPage.title ? ',' + text.replace(/\\]/g, ']') : ''}>>` | ||
}) | ||
return attachment ? `${siteUrl}${attachment.pub.url}[${text}]` : m | ||
return attachment && attachment.out | ||
? `${siteUrl}${attachment.pub.url.replace(/_/g, '{underscore}')}[${text}]` | ||
: m | ||
}) | ||
@@ -299,5 +321,5 @@ } | ||
// TODO: handle (or report) unresolved image better | ||
if (image) { | ||
if (image && image.out) { | ||
image.out.assembled = true | ||
return `image:${image.pub.url.substr(1)}[${attrlist}]` | ||
return `image:${image.out.path.replace(/_/g, '{underscore}')}[${attrlist}]` | ||
} | ||
@@ -359,5 +381,6 @@ } | ||
// FIXME: handle (or report) case when image is not resolved | ||
if (image) { | ||
lines[idx] = `${prefix}image::${image.pub.url.substr(1)}${line.substr(line.indexOf('['))}` | ||
if (image && image.out) { | ||
const boxedAttrlist = line.substr(line.indexOf('[')) | ||
image.out.assembled = true | ||
lines[idx] = `${prefix}image::${image.out.path}${boxedAttrlist}` | ||
} | ||
@@ -512,3 +535,3 @@ } | ||
prevLine = `[${ | ||
replacementStyle ? rawStyle.replace(/^[^.%]*]/, replacementStyle) : rawStyle | ||
replacementStyle ? rawStyle.replace(/^[^.%]*/, replacementStyle) : rawStyle | ||
}#${idprefix}${block.getId()}${prevLine.substr(rawStyle.length + 1)}` | ||
@@ -515,0 +538,0 @@ } |
'use strict' | ||
const File = require('vinyl') | ||
const filterComponentVersions = require('./filter-component-versions') | ||
@@ -10,4 +11,5 @@ const produceAggregateDocument = require('./produce-aggregate-document') | ||
const assemblerAsciiDocAttributes = Object.assign({}, assemblerAsciiDocConfig.attributes) | ||
const { doctype, 'source-highlighter': sourceHighlighter } = assemblerAsciiDocAttributes | ||
const { doctype, revdate, 'source-highlighter': sourceHighlighter } = assemblerAsciiDocAttributes | ||
delete assemblerAsciiDocAttributes.doctype | ||
delete assemblerAsciiDocAttributes.revdate | ||
delete assemblerAsciiDocAttributes['source-highlighter'] | ||
@@ -20,3 +22,3 @@ return filterComponentVersions(contentCatalog.getComponents(), assemblerConfig.componentVersions).reduce( | ||
const mergedAsciiDocConfig = Object.assign({}, componentVersionAsciiDocConfig, { | ||
attributes: Object.assign({}, componentVersionAsciiDocConfig.attributes, assemblerAsciiDocAttributes), | ||
attributes: Object.assign({ revdate }, componentVersionAsciiDocConfig.attributes, assemblerAsciiDocAttributes), | ||
}) | ||
@@ -33,6 +35,12 @@ const rootEntry = { content: title } | ||
} | ||
// Q: should we use an artificial page instead or as fallback? | ||
const mutableAttributes = startPage | ||
? selectMutableAttributes(loadAsciiDoc, contentCatalog, startPage, mergedAsciiDocConfig) | ||
: {} | ||
// Q: should we always use a reference page here? | ||
const startPage_ = | ||
startPage ?? | ||
createFile({ | ||
component: componentVersion.name, | ||
version: componentVersion.version, | ||
relative: '.reference-page.adoc', | ||
origin: (componentVersion.origins || [])[0], | ||
}) | ||
const mutableAttributes = selectMutableAttributes(loadAsciiDoc, contentCatalog, startPage_, mergedAsciiDocConfig) | ||
delete mutableAttributes.doctype | ||
@@ -64,2 +72,26 @@ accum = accum.concat( | ||
function createFile (src) { | ||
const familySegment = (src.family ??= 'page') + 's' | ||
const path = `modules/${(src.module ??= 'ROOT')}/${familySegment}/${src.relative}` | ||
const moduleRootPath = Array(src.relative.split('/').length - 1) | ||
.fill('..') | ||
.join('/') | ||
const outPath = [ | ||
src.component === 'ROOT' ? '' : src.component, | ||
src.version, | ||
src.module === 'ROOT' ? '' : src.module, | ||
src.family === 'page' ? '' : '_' + familySegment, | ||
src.family === 'page' ? src.relative.replace(/\.adoc$/, '.html') : src.relative, | ||
] | ||
.filter((it) => it) | ||
.join('/') | ||
return new File({ | ||
path, | ||
contents: src.contents ?? Buffer.alloc(0), | ||
src, | ||
out: { path: outPath }, | ||
pub: { url: '/' + outPath, moduleRootPath }, | ||
}) | ||
} | ||
function getAsciiDocConfigWithAsciidoctorReducerExtension (componentVersion) { | ||
@@ -88,2 +120,5 @@ const asciidoctorReducerExtension = require('./asciidoctor/reducer-extension') // NOTE: must be required lazily | ||
// when root level is 0, merge the navigation into the rootEntry | ||
// when root level is 1, create navigation per navigation menu | ||
// in this case, if there's only a single navigation menu with no title, promote each top-level item to a menu | ||
function prepareOutlines (navigation, rootEntry, rootLevel) { | ||
@@ -95,3 +130,3 @@ if (rootLevel === 0 || navigation.length === 1) { | ||
: { items: navigation.reduce((navTree, it) => navTree.concat(it.content ? it : it.items), []) } | ||
return [Object.assign(rootEntry, navBranch)] | ||
return rootLevel === 0 || navBranch.content ? [Object.assign(rootEntry, navBranch)] : navBranch.items | ||
} | ||
@@ -98,0 +133,0 @@ return navigation.reduce((navTree, it) => navTree.concat(it.content ? it : it.items), [rootEntry]) |
'use strict' | ||
const { PassThrough } = require('stream') | ||
const { PassThrough } = require('node:stream') | ||
@@ -5,0 +5,0 @@ // adapted from https://github.com/jpommerening/node-lazystream/blob/master/lib/lazystream.js | license: MIT |
'use strict' | ||
const fs = require('fs') | ||
const fs = require('node:fs') | ||
const LazyReadable = require('./lazy-readable') | ||
const { spawn } = require('child_process') | ||
const { spawn } = require('node:child_process') | ||
@@ -7,0 +7,0 @@ const IS_WIN = process.platform === 'win32' |
{ | ||
"name": "@antora/assembler", | ||
"version": "1.0.0-alpha.6", | ||
"version": "1.0.0-alpha.7", | ||
"description": "An extension library for Antora that assembles content from multiple pages into a single AsciiDoc file to converted and publish.", | ||
@@ -34,3 +34,3 @@ "license": "MPL-2.0", | ||
"braces": "~3.0", | ||
"picomatch": "~2.3", | ||
"picomatch": "~3.0", | ||
"vinyl": "~2.2", | ||
@@ -37,0 +37,0 @@ "js-yaml": "~4.1" |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
51003
1194
1
0
+ Addedpicomatch@3.0.1(transitive)
- Removedpicomatch@2.3.1(transitive)
Updatedpicomatch@~3.0