@antora/assembler 1.0.0-rc.11 → 1.0.0-rc.12

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.
@@ -232,15 +232,20 @@ function mergeAsciiDoc (
232
232
  return builder
233
233
  }
234
234
  const assembled = pagesInOutline.assembled
235
+ const atStartOfBody = !builder.body?.length
236
+ const isRootEntry = atStartOfBody && !level
235
237
  // FIXME: ideally, resource ID would be stored in navigation so we can look up the page more efficiently
236
238
  const page = urlType === 'internal' && !unresolved ? pagesInOutline.get(pathname) : undefined
237
- let navtitle = outlineEntry.navtitle ?? (page && hash ? page.asciidoc.navtitle : outlineEntry.content)
239
+ let navtitle = outlineEntry.content
240
+ if (isRootEntry && 'navtitle' in outlineEntry) {
241
+ navtitle = outlineEntry.navtitle
242
+ } else if (page && hash) {
243
+ navtitle = page.asciidoc.navtitle
244
+ }
238
245
  let navtitleAsciiDoc = unconvertInlineAsciiDoc(navtitle)
239
246
  let navtitlePlain = sanitize(navtitle)
240
247
  const { doctype, filetype, linkReferenceStyle, pubRoot, siteRoot, logger, rootLevel, rootPageStyle } = assemblyModel
241
248
  let sectionMergeStrategy = assemblyModel.sectionMergeStrategy
242
- const atStartOfBody = !builder.body?.length
243
- const isRootEntry = atStartOfBody && !level
244
249
  let atBookRoot = isRootEntry && doctype === 'book' && (supportsParts = true)
245
250
  const hasItems = items.length > 0
246
251
  if (page && !assembled.pages.has(page)) {
@@ -386,13 +391,22 @@ function mergeAsciiDoc (
386
391
  }
387
392
  buffer.push(`:page-module: ${module_}`)
388
393
  buffer.push(`:page-relative-src-path: ${relative}`)
389
- buffer.push(`:page-origin-url: ${origin.url}`)
390
- buffer.push(`:page-origin-start-path:${origin.startPath && ' '}${origin.startPath}`)
391
- buffer.push(`:page-origin-refname: ${origin.branch || origin.tag}`)
392
- buffer.push(`:page-origin-reftype: ${origin.branch ? 'branch' : 'tag'}`)
393
- buffer.push(`:page-origin-refhash: ${origin.worktree ? '(worktree)' : origin.refhash}`)
394
+ if (origin) {
395
+ buffer.push(`:page-origin-url: ${origin.url}`)
396
+ buffer.push(`:page-origin-start-path:${origin.startPath && ' '}${origin.startPath}`)
397
+ buffer.push(`:page-origin-refname: ${origin.branch || origin.tag}`)
398
+ buffer.push(`:page-origin-reftype: ${origin.branch ? 'branch' : 'tag'}`)
399
+ buffer.push(`:page-origin-refhash: ${origin.worktree ? '(worktree)' : origin.refhash}`)
400
+ } else {
401
+ buffer.push(':!page-origin-url:')
402
+ buffer.push(':!page-origin-start-path:')
403
+ buffer.push(':!page-origin-refname:')
404
+ buffer.push(':!page-origin-reftype:')
405
+ buffer.push(':!page-origin-refhash:')
406
+ }
407
+ buffer.push(`:page-url: ${page.pub.url}`)
394
408
  let heading
395
- if (pageStyle != null && isRootPage) {
409
+ if (isRootPage && pageStyle != null) {
396
410
  let htitleAsciiDoc, htitleOverride
397
411
  if (pageStyle === 'preface') {
398
412
  const hasPrefaceTitleAttr =
@@ -459,26 +473,24 @@ function mergeAsciiDoc (
459
473
  heading = { title: navtitleAsciiDoc, hlevel: level-- } // NOTE: level will always come in at 1
460
474
  nextSectionLevel = pageStyle === 'part' ? 1 : 2
461
475
  } else if (level) {
462
- if (atStartOfBody && !pageStyle && builder.matchesDoctitle(navtitlePlain)) {
476
+ if (atStartOfBody && pageStyle == null && !headerHasBlockAttrs && builder.matchesDoctitle(navtitlePlain)) {
463
477
  level--
464
- if (headerHasBlockAttrs) heading = { title: '', hlevel: ++level + 1 }
465
- } else {
466
- heading = { title: navtitleAsciiDoc, hlevel: level + 1 }
478
+ } else if ((heading = { title: navtitleAsciiDoc, hlevel: level + 1 }).hlevel > 6) {
479
+ Object.assign(heading, { hlevel: 6, style: `discrete.h${heading.hlevel}` })
467
480
  }
468
481
  }
469
482
  if (heading) {
470
- if (heading.hlevel > 6) Object.assign(heading, { hlevel: 6, style: `discrete.h${heading.hlevel}` })
471
483
  const rolesAttr = pageRoles.reduce((str, it) => str + '.' + it, '')
472
484
  const notitle = (heading.title ||= '{empty}') === '{empty}'
473
485
  // remove conditional if we always want to promote ID of root page to docid
474
- if (notitle && atStartOfBody) {
486
+ if (atStartOfBody && notitle) {
475
487
  builder.setDocid(pageId)
476
488
  pageFragment = '#' + idSeparators.generateIdFromTitle('', idSeparators, pageIdLeader)
477
489
  }
478
490
  const style = heading.style ?? (pageStyle === 'part' || pageStyle === 'section' ? '' : (pageStyle ?? ''))
479
491
  buffer.push(`[${style}${pageFragment}${rolesAttr}${notitle ? '%notitle' : ''}]`)
480
492
  buffer.push(`${'='.repeat(heading.hlevel)} ${heading.title}`)
481
- if (notitle || !supportsSections) sectionMergeStrategy = 'discrete'
493
+ if ((notitle && pageStyle != null) || !supportsSections) sectionMergeStrategy = 'discrete'
482
494
  } else if (atStartOfBody) {
483
495
  builder.setDocid(pageId)
484
496
  }
@@ -39,7 +39,7 @@ function produceAssemblyFiles (
39
39
  const { attributes: assemblyAttributes, logger, navigation, rootLevel } = assemblyModel
40
40
  if (!navigation) return accum
41
41
  const contextualLogger = logger ? { warn: logger.warn.bind(logger, configMdc) } : undefined
42
- const { name: componentName, version, title } = componentVersion
42
+ const { name: componentName, version } = componentVersion
43
43
  const asciidocConfig = getAsciiDocConfigWithAsciidoctorReducerExtension(componentVersion, reducerExtension)
44
44
  let sourceHighlighter
45
45
  if ('source-highlighter' in assemblyAttributes) {
@@ -83,10 +83,9 @@ function produceAssemblyFiles (
83
83
  } else if (!(assemblyModel.filetype === 'pdf' && assemblyModel.linkReferenceStyle === 'relative')) {
84
84
  assemblyModel.linkReferenceStyle = 'absolute'
85
85
  }
86
- const outlineRoot = { content: title }
87
- const startPage = resolveStartPage(contentCatalog, componentVersion, assemblyModel.insertStartPage, outlineRoot)
86
+ const [startPage, outlineRoot] = resolveStartPage(contentCatalog, componentVersion, assemblyModel.insertStartPage)
88
87
  const mutableAttributes = identifyMutableAttributes(loadAsciiDoc, contentCatalog, startPage, mergedAsciiDocConfig)
89
- prepareOutlines(navigation, outlineRoot, rootLevel).reduce((any, outline) => {
88
+ prepareOutlines(navigation, outlineRoot, rootLevel).forEach((outline) => {
90
89
  const assemblyFile = produceAssemblyFile(
91
90
  loadAsciiDoc,
92
91
  contentCatalog,
@@ -97,15 +96,15 @@ function produceAssemblyFiles (
97
96
  mutableAttributes,
98
97
  assemblyModel
99
98
  )
100
- if (!assemblyFile) return any
99
+ if (!assemblyFile) return
101
100
  // NOTE restore source highlighter for conversion if defined in Assembler config
102
101
  if (sourceHighlighter !== undefined) {
103
102
  assemblyFile.asciidoc.attributes['source-highlighter'] = sourceHighlighter
104
103
  } else if (assemblyModel.filetype !== 'html') {
105
104
  delete assemblyFile.asciidoc.attributes['source-highlighter']
106
105
  }
107
- return !!accum.push(assemblyFile)
108
- }, false)
106
+ accum.push(assemblyFile)
107
+ })
109
108
  return accum
110
109
  }, [])
111
110
  }
@@ -129,53 +128,67 @@ function includedInNav (items, url) {
129
128
  return items.find((it) => it.url === url || includedInNav(it.items || [], url))
130
129
  }
131
130
 
132
- function resolveStartPage (contentCatalog, componentVersion, insertStartPage, outlineRoot) {
133
- const { name: componentName, version } = componentVersion
134
- const startPage =
131
+ function resolveStartPage (contentCatalog, componentVersion, insertStartPage) {
132
+ const { name: componentName, version, title } = componentVersion
133
+ const outlineRoot = { content: title }
134
+ let startPage =
135
135
  'startPage' in componentVersion
136
136
  ? componentVersion.startPage
137
137
  : contentCatalog.resolvePage('index.adoc', { component: componentName, version })
138
138
  if (startPage && startPage.src.component === componentName && startPage.src.version === version) {
139
- if (insertStartPage) {
140
- const navtitle = startPage.asciidoc?.navtitle || outlineRoot.content
141
- Object.assign(outlineRoot, { navtitle, url: startPage.pub.url, urlType: 'internal', roles: ['page'] })
142
- }
143
- return startPage
139
+ const navtitle = startPage.asciidoc?.navtitle ?? outlineRoot.content
140
+ Object.defineProperty(outlineRoot, 'startPageEntry', {
141
+ value: { navtitle, url: startPage.pub.url, urlType: 'internal', roles: ['page'] },
142
+ })
143
+ if (insertStartPage) Object.defineProperty(outlineRoot.startPageEntry, 'insert', { value: true })
144
+ } else {
145
+ startPage = contentCatalog.createFile({
146
+ src: {
147
+ component: componentName,
148
+ version,
149
+ componentVersion,
150
+ module: 'ROOT',
151
+ family: 'page',
152
+ relative: 'index.adoc',
153
+ origin: componentVersion.origins?.values().next().value,
154
+ },
155
+ })
144
156
  }
145
- return contentCatalog.createFile({
146
- src: {
147
- component: componentName,
148
- version,
149
- componentVersion,
150
- module: 'ROOT',
151
- family: 'page',
152
- relative: 'index.adoc',
153
- origin: componentVersion.origins?.values().next().value,
154
- },
155
- })
157
+ return [startPage, outlineRoot]
156
158
  }
157
159
 
158
160
  function prepareOutlines (navigation, rootEntry, rootLevel) {
159
- const singleEntry = navigation.length === 1
161
+ const startPageEntry = rootEntry.startPageEntry
162
+ const singleListWithTitle = navigation.length === 1 && 'content' in navigation[0] ? navigation[0] : undefined
163
+ if (singleListWithTitle) {
164
+ const { content, url, urlType } = singleListWithTitle
165
+ if (urlType === 'internal') {
166
+ if (startPageEntry && url === startPageEntry.url) {
167
+ if (!startPageEntry.insert) Object.defineProperty(startPageEntry, 'insert', { value: true })
168
+ //if (!(content === startPageEntry.content || content === startPageEntry.navtitle)) {
169
+ // startPageEntry.content = content
170
+ //}
171
+ startPageEntry.roles = singleListWithTitle.roles
172
+ navigation = [{ items: singleListWithTitle.items }]
173
+ }
174
+ } else if (content === rootEntry.content) {
175
+ delete Object.assign(rootEntry, singleListWithTitle).items
176
+ navigation = [{ items: singleListWithTitle.items }]
177
+ }
178
+ }
160
179
  const items = navigation.reduce((accum, it) => {
161
- if (!it.content || (singleEntry && it.url ? it.url === rootEntry.url : it.content === rootEntry.content)) {
162
- it.items && accum.push(...it.items)
163
- } else {
180
+ if ('content' in it) {
164
181
  accum.push(it)
182
+ } else if (it.items) {
183
+ accum.push(...it.items)
165
184
  }
166
185
  return accum
167
186
  }, [])
168
- if (rootLevel === 0) {
169
- if (rootEntry.url && includedInNav(items, rootEntry.url)) {
170
- for (const p of ['roles', 'url', 'urlType']) delete rootEntry[p]
171
- }
172
- return [Object.assign(rootEntry, { index: true, items })]
173
- }
174
- if (rootEntry.url && !includedInNav(items, rootEntry.url)) {
175
- rootEntry.content = singleEntry && rootEntry.url === navigation[0].url ? navigation[0].content : rootEntry.navtitle
176
- items.unshift(rootEntry)
187
+ if (startPageEntry?.insert && !includedInNav(items, startPageEntry.url)) {
188
+ Object.assign(rootEntry, startPageEntry)
189
+ if (rootLevel !== 0) items.unshift(Object.assign(rootEntry, { content: rootEntry.navtitle }))
177
190
  }
178
- return items
191
+ return rootLevel === 0 ? [Object.assign(rootEntry, { items })] : items
179
192
  }
180
193
 
181
194
  function extractUrlPath (url) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/assembler",
3
- "version": "1.0.0-rc.11",
3
+ "version": "1.0.0-rc.12",
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)",
@@ -39,12 +39,12 @@
39
39
  "@antora/expand-path-helper": "~3.0",
40
40
  "@antora/run-command-helper": "~1.1",
41
41
  "@asciidoctor/reducer": "~1.1",
42
- "js-yaml": "~5.3"
42
+ "js-yaml": "~5.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@antora/asciidoc-loader": "3.2.0-rc.3",
46
- "@antora/navigation-builder": "3.2.0-rc.3",
47
- "@antora/site-publisher": "3.2.0-rc.3"
45
+ "@antora/asciidoc-loader": "~3.2",
46
+ "@antora/navigation-builder": "~3.2",
47
+ "@antora/site-publisher": "~3.2"
48
48
  },
49
49
  "engines": {
50
50
  "node": ">=20.0.0"