@antora/assembler 1.0.0-rc.3 → 1.0.0-rc.4

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.
@@ -25,8 +25,8 @@ async function assembleContent (playbook, contentCatalog, converter, { configSou
25
25
  mediaType: targetMediaType,
26
26
  loggerName = PACKAGE_NAME,
27
27
  } = converter ?? {}
28
- const assemblerConfig = await loadConfig.call(this, playbook, configSource, '-' + targetBackend)
29
- if (assemblerConfig.enabled === false) return []
28
+ const assemblerConfig = await loadConfig.call(this, configSource, playbook, '-' + targetBackend)
29
+ if (assemblerConfig.enabled === false || !contentCatalog.publishableFamilies?.has('export')) return []
30
30
  const context = isBound(this)
31
31
  ? this
32
32
  : {
@@ -40,7 +40,7 @@ async function assembleContent (playbook, contentCatalog, converter, { configSou
40
40
  assemblyConfig.embedReferenceStyle = embedReferenceStyle
41
41
  const profile = (assemblyConfig.profile ??= targetBackend)
42
42
  const intrinsicAttributes = { 'loader-assembler': '' }
43
- buildConfig.cwd ??= process.cwd()
43
+ const cwd = (buildConfig.cwd ??= process.cwd())
44
44
  if (profile) {
45
45
  buildConfig.dir ??= ospath.join(playbook.dir ?? process.cwd(), `build/assembler/${profile}`)
46
46
  intrinsicAttributes[`assembler-profile-${profile}`] = ''
@@ -65,7 +65,7 @@ async function assembleContent (playbook, contentCatalog, converter, { configSou
65
65
  generateSelectAssemblyProfile(context, contentCatalog, assemblyConfig, intrinsicAttributes, navigationCatalog)
66
66
  )
67
67
  if (!(assemblyFiles.length && typeof convert === 'function')) return assemblyFiles
68
- buildConfig.command ??= typeof getDefaultCommand === 'function' ? await getDefaultCommand(buildConfig.cwd) : null
68
+ buildConfig.command ??= typeof getDefaultCommand === 'function' ? await getDefaultCommand(cwd, playbook) : null
69
69
  const { publishSite: publishFiles = require('@antora/site-publisher') } = generatorFunctions
70
70
  await prepareWorkspace(publishFiles, assemblyFiles, buildConfig)
71
71
  const helpers = { logCommand: logCommand.bind(context, loggerName), runCommand }
@@ -10,7 +10,7 @@ const { LEGACY_ASSEMBLY_KEYS } = require('./constants')
10
10
  const CAMEL_CASE_STOP_PATHS = ['asciidoc.attributes', 'assembly.attributes']
11
11
  const PACKAGE_NAME = require('../package.json').name
12
12
 
13
- function loadConfig (playbook, configSource, preferredQualifier = '') {
13
+ function loadConfig (configSource, playbook, preferredQualifier = '') {
14
14
  let resolvedConfigSource
15
15
  return (
16
16
  configSource?.constructor === Object
@@ -365,10 +365,10 @@ function mergeAsciiDoc (
365
365
  }
366
366
  }
367
367
  }
368
- if (htitleAsciiDoc != null) {
368
+ if (htitleAsciiDoc) {
369
369
  if (atDocumentRoot) {
370
- // NOTE use pageStyle as fallback because this section must have a unique ID
371
- pageFragment = `#${pageIdLeader}${doc.getId() ?? pageStyle}`
370
+ // Q: should we use htitleAsciiDoc to generate ID if not {empty} instead of pageStyle
371
+ pageFragment = `#_${idSeparators.coordinate}${pageIdLeader}${pageStyle}`
372
372
  buffer.unshift(`[#${pageId}]`)
373
373
  } else {
374
374
  pageFragment = `#${pageId}`
@@ -393,31 +393,30 @@ function mergeAsciiDoc (
393
393
  } else if (atBookRoot) {
394
394
  nextSectionLevel = undefined
395
395
  }
396
- let enclosed
397
396
  if (heading) {
398
397
  const rolesAttr = pageRoles.reduce((str, it) => str + '.' + it, '')
399
398
  const notitleAttrs = heading.notitle ? '%notitle,toclevels=0,outlinelevels=0' : ''
400
399
  buffer.push(`[${heading.style ?? pageStyle}${pageFragment}${rolesAttr}${notitleAttrs}]`)
401
400
  buffer.push(`${'='.repeat(heading.level)} ${heading.title}`)
402
- } else {
403
- if (atDocumentRoot) buffer.unshift(`[#${pageId}]`)
404
- if (sectionMergeStrategy === 'enclose' && hasItems && hasSections) {
405
- enclosed = true
406
- // TODO: make overview section title configurable
407
- //let overviewTitle = doc.getDocumentTitle()
408
- //if (overviewTitle === navtitle) overviewTitle = doc.getAttribute('overview-title', 'Overview')
409
- const overviewTitle = doc.getAttribute('overview-title', 'Overview')
410
- const syntheticId = idSeparators.generateIdFromTitle(navtitleAsciiDoc, idSeparators)
411
- let hlevel = level + 2
412
- if (hlevel > 6) {
413
- const blockStyle = `discrete.h${hlevel}`
414
- hlevel = 6
415
- buffer.push(`[${blockStyle}#${syntheticId}]`)
416
- } else {
417
- buffer.push(`[#${syntheticId}]`)
418
- }
419
- buffer.push(`${'='.repeat(hlevel)} ${overviewTitle}`)
401
+ } else if (atDocumentRoot) {
402
+ buffer.unshift(`[#${pageId}]`)
403
+ }
404
+ if (sectionMergeStrategy === 'enclose' && hasItems && hasSections && !(atDocumentRoot && heading)) {
405
+ // TODO: make overview section title configurable
406
+ //let overviewTitle = doc.getDocumentTitle()
407
+ //if (overviewTitle === navtitle) overviewTitle = doc.getAttribute('overview-title', 'Overview')
408
+ const overviewTitle = doc.getAttribute('overview-title', 'Overview')
409
+ const syntheticId = idSeparators.generateIdFromTitle(overviewTitle, idSeparators, pageIdLeader)
410
+ if (heading) buffer.push('')
411
+ let hlevel = level + (nextSectionLevel = 2)
412
+ if (hlevel > 6) {
413
+ const blockStyle = `discrete.h${hlevel}`
414
+ hlevel = 6
415
+ buffer.push(`[${blockStyle}#${syntheticId}]`)
416
+ } else {
417
+ buffer.push(`[#${syntheticId}]`)
420
418
  }
419
+ buffer.push(`${'='.repeat(hlevel)} ${overviewTitle}`)
421
420
  }
422
421
  assembled.pages.set(page, pageFragment)
423
422
  if (hasSections) fixSectionLevels(doc.getSections(), nextSectionLevel)
@@ -545,7 +544,7 @@ function mergeAsciiDoc (
545
544
  if (block.getSectionName() === 'header') return
546
545
  let blockStyle = sectionMergeStrategy === 'discrete' ? 'discrete' : undefined
547
546
  lines[idx] = lines[idx].replace(/^=+ (.+)/, (_, rest) => {
548
- let targetMarkerLength = block.level + 1 + level + (enclosed ? 1 : 0)
547
+ let targetMarkerLength = block.level + 1 + level
549
548
  if (targetMarkerLength > 6) {
550
549
  blockStyle = `discrete.h${targetMarkerLength}`
551
550
  targetMarkerLength = 6
@@ -806,9 +805,10 @@ function safePush (onto, entries) {
806
805
  }
807
806
  }
808
807
 
809
- function generateIdFromTitle (titleAsciiDoc, idSeparators) {
808
+ function generateIdFromTitle (titleAsciiDoc, idSeparators, idLeader) {
810
809
  const Section = this.$class().$const_get('::Asciidoctor::Section')
811
810
  const baseId = Section.$generate_id(titleAsciiDoc, this)
811
+ if (idLeader) return `_${idSeparators.coordinate}${idLeader}${baseId}`
812
812
  this.getCatalog().refs['$[]='](baseId, true)
813
813
  return `_${idSeparators.coordinate}${baseId}`
814
814
  }
@@ -6,6 +6,7 @@ function generateScopedId (componentSrc, componentVersion, separators, filetype,
6
6
  let { component, module: mod, relative } = componentSrc
7
7
  let id = relative.replace(/\.adoc$/, '').replace(/[/.]/g, '-')
8
8
  let { coordinate: coordinateSeparator, prefix: prefixSeparator } = separators
9
+ if (mod !== 'ROOT' && ~mod.indexOf('.')) mod = mod.replace(/[.]/g, '-')
9
10
  if (component !== componentVersion.name) {
10
11
  id = [component, mod === 'ROOT' ? '' : mod, id].join(coordinateSeparator)
11
12
  } else if (mod !== 'ROOT') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/assembler",
3
- "version": "1.0.0-rc.3",
3
+ "version": "1.0.0-rc.4",
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)",