@antora/assembler 1.0.0-rc.7 → 1.0.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/assemble-content.js
CHANGED
|
@@ -78,7 +78,13 @@ async function assembleContent (playbook, contentCatalog, converter, providers)
|
|
|
78
78
|
buildConfig.command ??= typeof getDefaultCommand === 'function' ? await getDefaultCommand(cwd, playbook) : null
|
|
79
79
|
const { publishSite: publishFiles = context.require('@antora/site-publisher') } = generatorFunctions
|
|
80
80
|
await prepareWorkspace(publishFiles, assemblyFiles, buildConfig)
|
|
81
|
-
const helpers = {
|
|
81
|
+
const helpers = { runCommand }
|
|
82
|
+
Object.defineProperty(helpers, 'logger', {
|
|
83
|
+
get: () => context?.getLogger(loggerName),
|
|
84
|
+
})
|
|
85
|
+
Object.defineProperty(helpers, 'logCommand', {
|
|
86
|
+
get: () => logCommand.bind(null, helpers.logger),
|
|
87
|
+
})
|
|
82
88
|
const boundConvert = convert.bind(context)
|
|
83
89
|
const boundResolveFileOrContents = resolveFileOrContents.bind(context)
|
|
84
90
|
return new PromiseQueue({ concurrency: buildConfig.processLimit })
|
|
@@ -116,6 +122,7 @@ async function assembleContent (playbook, contentCatalog, converter, providers)
|
|
|
116
122
|
const assemblerMeta = (page.assembler ??= {})
|
|
117
123
|
const exports = (assemblerMeta.exports ??= [])
|
|
118
124
|
const exportEntry = { fragment, file }
|
|
125
|
+
if (fragment === pages.rootPageFragment) exportEntry.root = true
|
|
119
126
|
const insertIdx = exports.findIndex(
|
|
120
127
|
({ file: candidate }) =>
|
|
121
128
|
!(candidate.src.component === page.src.component && candidate.src.version === page.src.version)
|
|
@@ -12,16 +12,18 @@ async function compileConversionAttributes (doc, targetExtname, assemblerConfig,
|
|
|
12
12
|
} = doc
|
|
13
13
|
const { cwd = process.cwd(), dir = cwd, mkdirs } = assemblerConfig.build
|
|
14
14
|
const docname = family + '$' + relative.substring(0, relative.length - docfilesuffix.length)
|
|
15
|
-
const docfile = ospath.join(dir, reldocfile)
|
|
15
|
+
const docfile = (doc.src.path = ospath.join(dir, reldocfile))
|
|
16
16
|
const outdir = ospath.dirname(docfile)
|
|
17
17
|
const outfile = docfile.substring(0, docfile.length - docfilesuffix.length) + targetExtname
|
|
18
|
+
const docdir = relativeToOutput ? dir : outdir
|
|
19
|
+
const imagesoutdir = ospath.join(outdir, '..', '_images')
|
|
18
20
|
const attributes = Object.assign({ revdate: `${assemblerConfig.assembly.revdate}@` }, docAttributes, {
|
|
19
|
-
docdir
|
|
21
|
+
docdir,
|
|
20
22
|
docfile,
|
|
21
23
|
docfilesuffix,
|
|
22
24
|
docname: `${docname}@`,
|
|
23
25
|
imagesdir: '',
|
|
24
|
-
imagesoutdir
|
|
26
|
+
imagesoutdir,
|
|
25
27
|
outdir,
|
|
26
28
|
outfile,
|
|
27
29
|
outfilesuffix: targetExtname,
|
package/lib/log-command.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
function logCommand (
|
|
4
|
-
const logger = this?.getLogger(loggerName)
|
|
3
|
+
function logCommand (logger, command, extraArgsOrAttributeOptionFlag, file, attributes) {
|
|
5
4
|
if (!logger?.isLevelEnabled('debug')) return
|
|
6
|
-
const { docfile, 'assembler-filetype': filetype } = attributes
|
|
7
5
|
const args = (
|
|
8
6
|
Array.isArray(extraArgsOrAttributeOptionFlag)
|
|
9
7
|
? extraArgsOrAttributeOptionFlag
|
|
@@ -11,10 +9,10 @@ function logCommand (loggerName, command, extraArgsOrAttributeOptionFlag, file,
|
|
|
11
9
|
? attributes.toArgs(extraArgsOrAttributeOptionFlag)
|
|
12
10
|
: []
|
|
13
11
|
).map((it) => (~it.indexOf(' ') ? `'${it}'` : it))
|
|
14
|
-
const ctx = { command: [command].concat(args).join(' '), file:
|
|
12
|
+
const ctx = { command: [command].concat(args).join(' '), file: file.src }
|
|
15
13
|
const msg = `Running external command to export assembly in %s to %s: %s`
|
|
16
14
|
const componentVersionStr = file.src.version ? `${file.src.version}@${file.src.component}` : file.src.component
|
|
17
|
-
logger.debug(ctx, msg, componentVersionStr, filetype, file.src.relative)
|
|
15
|
+
logger.debug(ctx, msg, componentVersionStr, attributes['assembler-filetype'], file.src.relative)
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
module.exports = logCommand
|
|
@@ -44,9 +44,13 @@ function produceAssemblyFile (
|
|
|
44
44
|
const pagesByUrl = files.reduce((map, it) => (it.src.family === 'page' ? map.set(it.pub.url, it) : map), new Map())
|
|
45
45
|
const pagesInOutline = selectPagesInOutline(outline, pagesByUrl)
|
|
46
46
|
if (outline.urlType === 'internal' && !pagesByUrl.has(outline.pathname) && !outline.items?.length) return
|
|
47
|
+
const { name: component, version } = componentVersion
|
|
47
48
|
const { rootLevel, xmlIds } = assemblyModel
|
|
48
49
|
const scratchDoc = loadAsciiDoc(
|
|
49
|
-
{
|
|
50
|
+
{
|
|
51
|
+
contents: Buffer.alloc(0),
|
|
52
|
+
src: { component, version, module: 'ROOT', family: 'page', relative: '_.adoc', path: '_.adoc' },
|
|
53
|
+
},
|
|
50
54
|
undefined,
|
|
51
55
|
asciidocConfig
|
|
52
56
|
)
|
|
@@ -57,7 +61,6 @@ function produceAssemblyFile (
|
|
|
57
61
|
coordinate: xmlIds ? '----' : ':',
|
|
58
62
|
generateIdFromTitle: generateIdFromTitle.bind(scratchDoc),
|
|
59
63
|
}
|
|
60
|
-
const { name: component, version } = componentVersion
|
|
61
64
|
asciidocConfig = prepareAsciiDocConfig(
|
|
62
65
|
contentCatalog,
|
|
63
66
|
{ component, version },
|
|
@@ -92,7 +95,7 @@ function produceAssemblyFile (
|
|
|
92
95
|
src: { component, version, componentVersion, module: 'ROOT', family: 'export', relative: stem + '.adoc' },
|
|
93
96
|
pub: false,
|
|
94
97
|
})
|
|
95
|
-
file.path = file.
|
|
98
|
+
file.path = file.out.path // use out path as path so assets can be published to same hierarchy
|
|
96
99
|
delete file.out
|
|
97
100
|
return file
|
|
98
101
|
}
|
|
@@ -232,7 +235,7 @@ function mergeAsciiDoc (
|
|
|
232
235
|
return builder
|
|
233
236
|
}
|
|
234
237
|
const pageAsAsciiDoc = new page.constructor(
|
|
235
|
-
Object.assign({}, page, { contents:
|
|
238
|
+
Object.assign({}, page, { contents: Buffer.from(contents.toString().trimEnd()), mediaType: page.src.mediaType })
|
|
236
239
|
)
|
|
237
240
|
const doc = loadAsciiDoc(pageAsAsciiDoc, contentCatalog, asciidocConfig)
|
|
238
241
|
doc.catalog.syntheticIds = {}
|
|
@@ -271,7 +274,7 @@ function mergeAsciiDoc (
|
|
|
271
274
|
const docname = doc.getAttribute('docname')
|
|
272
275
|
const pageId = generateScopedId(page.src, componentVersion, idSeparators, filetype)
|
|
273
276
|
const pageIdLeader = pageId + idSeparators.scope
|
|
274
|
-
let pageFragment =
|
|
277
|
+
let pageFragment = `#${pageId}`
|
|
275
278
|
let pageRoles = []
|
|
276
279
|
let pageStyle = doc.getAttribute('assembly-style', '')
|
|
277
280
|
if (!pageStyle && atBookRoot && rootLevel === 0 && !doc.source_header_attributes['$key?']('assembly-style')) {
|
|
@@ -324,7 +327,7 @@ function mergeAsciiDoc (
|
|
|
324
327
|
if (
|
|
325
328
|
name.endsWith('-image') &&
|
|
326
329
|
(val = doc.getAttribute(name)) &&
|
|
327
|
-
(newVal = rewriteImageAttr(val, contentCatalog, assemblyModel, page.src, assembled.assets))
|
|
330
|
+
(newVal = rewriteImageAttr(val, contentCatalog, assemblyModel, page.src, assembled.assets)) != null
|
|
328
331
|
) {
|
|
329
332
|
if (newVal !== val) entry.lines = [`:${name}: ${newVal}`]
|
|
330
333
|
} else if (~(val = entry.lines.join('\n').substring(name.length + 3)).indexOf(':')) {
|
|
@@ -403,8 +406,6 @@ function mergeAsciiDoc (
|
|
|
403
406
|
// Q: should we use htitleAsciiDoc to generate ID if not {empty} instead of pageStyle
|
|
404
407
|
pageFragment = `#_${idSeparators.coordinate}${pageIdLeader}${pageStyle}`
|
|
405
408
|
builder.setDocid(pageId)
|
|
406
|
-
} else {
|
|
407
|
-
pageFragment = `#${pageId}`
|
|
408
409
|
}
|
|
409
410
|
heading = { title: htitleAsciiDoc, level: part ? 1 : 2 }
|
|
410
411
|
if (notitle) heading.notitle = true
|
|
@@ -414,14 +415,12 @@ function mergeAsciiDoc (
|
|
|
414
415
|
if (atDocumentRoot && rootLevel === 0 && navtitlePlain === componentVersion.title && !hasAssemblyNavtitleAttr) {
|
|
415
416
|
level--
|
|
416
417
|
} else {
|
|
417
|
-
pageFragment = `#${pageId}`
|
|
418
418
|
if (part && level === 1) level--
|
|
419
419
|
if ((heading = { title: navtitleAsciiDoc, level: level + 1 }).level > 6) {
|
|
420
420
|
Object.assign(heading, { level: 6, style: `discrete.h${heading.level}` })
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
} else if (atDocumentRoot && rootLevel === 0 && hasAssemblyNavtitleAttr) {
|
|
424
|
-
pageFragment = `#${pageId}`
|
|
425
424
|
heading = { title: navtitleAsciiDoc, level: (nextSectionLevel = part ? 1 : 2) }
|
|
426
425
|
} else if (atBookRoot) {
|
|
427
426
|
nextSectionLevel = undefined
|
|
@@ -434,6 +433,8 @@ function mergeAsciiDoc (
|
|
|
434
433
|
} else if (atDocumentRoot) {
|
|
435
434
|
builder.setDocid(pageId)
|
|
436
435
|
}
|
|
436
|
+
if (isRootPage || (atDocumentRoot && !heading)) assembled.pages.rootPageFragment = pageFragment
|
|
437
|
+
assembled.pages.set(page, pageFragment)
|
|
437
438
|
if (sectionMergeStrategy === 'enclose' && hasItems && hasSections && !(atDocumentRoot && heading)) {
|
|
438
439
|
// TODO: make overview section title configurable
|
|
439
440
|
//let overviewTitle = doc.getDocumentTitle()
|
|
@@ -451,7 +452,6 @@ function mergeAsciiDoc (
|
|
|
451
452
|
}
|
|
452
453
|
buffer.push(`${'='.repeat(hlevel)} ${overviewTitle}`)
|
|
453
454
|
}
|
|
454
|
-
assembled.pages.set(page, pageFragment)
|
|
455
455
|
if (hasSections) fixSectionLevels(doc.getSections(), nextSectionLevel)
|
|
456
456
|
const allBlocks = doc.findBy({ traverse_documents: true }, (it) =>
|
|
457
457
|
it.getContext() === 'document'
|
|
@@ -822,24 +822,10 @@ function fixSectionLevels (sections, expectedLevel) {
|
|
|
822
822
|
})
|
|
823
823
|
}
|
|
824
824
|
|
|
825
|
-
// NOTE: blank lines at top and bottom of document create mismatch when using line numbers to navigate source lines
|
|
826
|
-
// IMPORTANT: this must not leave behind lines the parser will drop!
|
|
827
|
-
// IDEA: another option is to capture initial lineno of reader and use as offset (but preseves those blank lines)
|
|
828
|
-
function trimAsciiDoc (buffer) {
|
|
829
|
-
return Buffer.from(
|
|
830
|
-
buffer
|
|
831
|
-
.toString()
|
|
832
|
-
.replace(/^(?:[ \t]*\r\n?|[ \t]*\n)+/, '')
|
|
833
|
-
.trimRight()
|
|
834
|
-
)
|
|
835
|
-
}
|
|
836
|
-
|
|
837
825
|
function safePush (onto, entries) {
|
|
838
826
|
try {
|
|
839
827
|
onto.push(...entries)
|
|
840
|
-
} catch
|
|
841
|
-
/* istanbul ignore if */
|
|
842
|
-
if (!(err instanceof RangeError)) throw err
|
|
828
|
+
} catch {
|
|
843
829
|
for (const e of entries) onto.push(e)
|
|
844
830
|
}
|
|
845
831
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/assembler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.8",
|
|
4
4
|
"description": "A JavaScript library that merges AsciiDoc content from multiple pages in an Antora site into assembly files and delegates to an exporter to convert those files to another format, such as PDF.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|