@antora/content-classifier 3.0.3 → 3.1.0

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.
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const ContentCatalog = require('./content-catalog')
4
+ const collateAsciiDocAttributes = require('@antora/asciidoc-loader/config/collate-asciidoc-attributes')
4
5
 
5
6
  /**
6
7
  * Organizes the raw aggregate of virtual files into a {ContentCatalog}.
@@ -34,7 +35,7 @@ function classifyContent (playbook, aggregate, siteAsciiDocConfig = {}) {
34
35
  .forEach((componentVersionData, componentVersion) => {
35
36
  const { name, version } = componentVersion
36
37
  const { files, nav, startPage } = componentVersionData
37
- delete componentVersionData.files // clean up memory
38
+ componentVersionData.files = undefined // clean up memory
38
39
  files.forEach((file) => allocateSrc(file, name, version, nav) && contentCatalog.addFile(file))
39
40
  contentCatalog.registerComponentVersionStartPage(name, componentVersion, startPage)
40
41
  })
@@ -130,29 +131,15 @@ function getNavInfo (filepath, nav) {
130
131
  if (~index) return { index }
131
132
  }
132
133
 
133
- function resolveAsciiDocConfig (siteAsciiDocConfig, { asciidoc }) {
134
+ function resolveAsciiDocConfig (siteAsciiDocConfig, { asciidoc, origins = [] }) {
134
135
  const scopedAttributes = (asciidoc || {}).attributes
135
136
  if (scopedAttributes) {
136
- const siteAttributes = siteAsciiDocConfig.attributes
137
- if (siteAttributes) {
138
- const attributes = Object.keys(scopedAttributes).reduce((accum, name) => {
139
- if (name in siteAttributes) {
140
- const currentVal = siteAttributes[name]
141
- if (currentVal === false || String(currentVal).endsWith('@')) accum[name] = scopedAttributes[name]
142
- } else {
143
- accum[name] = scopedAttributes[name]
144
- }
145
- return accum
146
- }, {})
147
- return Object.keys(attributes).length
148
- ? Object.assign({}, siteAsciiDocConfig, { attributes: Object.assign({}, siteAttributes, attributes) })
149
- : siteAsciiDocConfig
150
- } else {
151
- return Object.assign({}, siteAsciiDocConfig, { attributes: scopedAttributes })
152
- }
153
- } else {
154
- return siteAsciiDocConfig
137
+ const initial = siteAsciiDocConfig.attributes
138
+ const mdc = { file: { path: 'antora.yml', origin: origins[origins.length - 1] } }
139
+ const attributes = collateAsciiDocAttributes(scopedAttributes, { initial, mdc, merge: true })
140
+ if (attributes !== initial) siteAsciiDocConfig = Object.assign({}, siteAsciiDocConfig, { attributes })
155
141
  }
142
+ return siteAsciiDocConfig
156
143
  }
157
144
 
158
145
  function calculateRootPath (depth) {
@@ -11,6 +11,7 @@ const versionCompare = require('./util/version-compare-desc')
11
11
 
12
12
  const { ROOT_INDEX_ALIAS_ID, ROOT_INDEX_PAGE_ID } = require('./constants')
13
13
  const SPACE_RX = / /g
14
+ const LOG_WRAP = '\n '
14
15
 
15
16
  const $components = Symbol('components')
16
17
  const $files = Symbol('files')
@@ -140,12 +141,12 @@ class ContentCatalog {
140
141
  throw new Error(`Duplicate alias: ${generateResourceSpec(src)}`)
141
142
  } else {
142
143
  const details = [filesForFamily.get(key), file]
143
- .map((it, idx) => ` ${idx + 1}: ${getFileLocation(it)}`)
144
- .join('\n')
144
+ .map((it, idx) => `${idx + 1}: ${getFileLocation(it)}`)
145
+ .join(LOG_WRAP)
145
146
  if (family === 'nav') {
146
- throw new Error(`Duplicate nav in ${src.version}@${src.component}: ${file.path}\n${details}`)
147
+ throw new Error(`Duplicate nav in ${src.version}@${src.component}: ${file.path}${LOG_WRAP}${details}`)
147
148
  } else {
148
- throw new Error(`Duplicate ${family}: ${generateResourceSpec(src)}\n${details}`)
149
+ throw new Error(`Duplicate ${family}: ${generateResourceSpec(src)}${LOG_WRAP}${details}`)
149
150
  }
150
151
  }
151
152
  }
@@ -189,6 +190,12 @@ class ContentCatalog {
189
190
  return file
190
191
  }
191
192
 
193
+ removeFile (file) {
194
+ const src = file.src
195
+ const filesForFamily = this[$files].get(src.family)
196
+ return filesForFamily ? filesForFamily.delete(generateKey(src)) : false
197
+ }
198
+
192
199
  findBy (criteria) {
193
200
  const criteriaEntries = Object.entries(criteria)
194
201
  const family = criteria.family
@@ -354,10 +361,10 @@ class ContentCatalog {
354
361
  throw new Error(
355
362
  existingPage === target
356
363
  ? `Page cannot define alias that references itself: ${generateResourceSpec(src)}` +
357
- ` (specified as: ${spec})\n source: ${getFileLocation(existingPage)}`
358
- : `Page alias cannot reference an existing page: ${generateResourceSpec(src)} (specified as: ${spec})\n` +
359
- ` source: ${getFileLocation(target)}\n` +
360
- ` existing page: ${getFileLocation(existingPage)}`
364
+ ` (specified as: ${spec})${LOG_WRAP}source: ${getFileLocation(existingPage)}`
365
+ : `Page alias cannot reference an existing page: ${generateResourceSpec(src)} (specified as: ${spec})` +
366
+ `${LOG_WRAP}source: ${getFileLocation(target)}` +
367
+ `${LOG_WRAP}existing page: ${getFileLocation(existingPage)}`
361
368
  )
362
369
  }
363
370
  } else if (src.version == null) {
@@ -368,7 +375,8 @@ class ContentCatalog {
368
375
  const existingAlias = this.getById(src)
369
376
  if (existingAlias) {
370
377
  throw new Error(
371
- `Duplicate alias: ${generateResourceSpec(src)} (specified as: ${spec})\n source: ${getFileLocation(target)}`
378
+ `Duplicate alias: ${generateResourceSpec(src)} (specified as: ${spec})` +
379
+ `${LOG_WRAP}source: ${getFileLocation(target)}`
372
380
  )
373
381
  }
374
382
  // NOTE the redirect producer will populate contents when the redirect facility is 'static'
@@ -587,10 +595,12 @@ function createSymbolicVersionAlias (component, version, symbolicVersionSegment,
587
595
  }
588
596
 
589
597
  function getFileLocation ({ path: path_, src: { abspath, origin } }) {
590
- return (
591
- abspath ||
592
- (origin ? `${path.join(origin.startPath, path_)} in ${origin.url} (ref: ${origin.branch || origin.tag})` : path_)
593
- )
598
+ if (!origin) return abspath || path_
599
+ const { url, gitdir, worktree, refname, tag, reftype = tag ? 'tag' : 'branch', remote, startPath } = origin
600
+ let details = `${reftype}: ${refname}`
601
+ if ('worktree' in origin) details += worktree ? ' <worktree>' : remote ? ` <remotes/${remote}>` : ''
602
+ if (startPath) details += ` | start path: ${startPath}`
603
+ return `${abspath || path.join(startPath, path_)} in ${'worktree' in origin ? worktree || gitdir : url} (${details})`
594
604
  }
595
605
 
596
606
  module.exports = ContentCatalog
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/content-classifier",
3
- "version": "3.0.3",
3
+ "version": "3.1.0",
4
4
  "description": "Organizes aggregated content into a virtual file catalog for use in an Antora documentation pipeline.",
5
5
  "license": "MPL-2.0",
6
6
  "author": "OpenDevise Inc. (https://opendevise.com)",
@@ -15,13 +15,25 @@
15
15
  "url": "https://gitlab.com/antora/antora/issues"
16
16
  },
17
17
  "main": "lib/index.js",
18
+ "exports": {
19
+ ".": "./lib/index.js",
20
+ "./content-catalog": "./lib/content-catalog.js",
21
+ "./file": "./lib/file.js",
22
+ "./util/*": "./lib/util/*.js",
23
+ "./lib/util/*": "./lib/util/*.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "imports": {
27
+ "#constants": "./lib/constants.js"
28
+ },
18
29
  "dependencies": {
19
- "@antora/logger": "3.0.3",
30
+ "@antora/asciidoc-loader": "3.1.0",
31
+ "@antora/logger": "3.1.0",
20
32
  "mime-types": "~2.1",
21
33
  "vinyl": "~2.2"
22
34
  },
23
35
  "engines": {
24
- "node": ">=12.21.0"
36
+ "node": ">=16.0.0"
25
37
  },
26
38
  "files": [
27
39
  "lib/"