@antora/content-classifier 3.2.0-alpha.5 → 3.2.0-alpha.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/classify-content.js
CHANGED
|
@@ -20,7 +20,7 @@ const summarizeFileLocation = require('./util/summarize-file-location')
|
|
|
20
20
|
*
|
|
21
21
|
* @returns {ContentCatalog} A structured catalog of content components, versions, and virtual content files.
|
|
22
22
|
*/
|
|
23
|
-
function classifyContent (playbook, aggregate, siteAsciiDocConfig = {}, onComponentsRegistered) {
|
|
23
|
+
function classifyContent (playbook, aggregate, siteAsciiDocConfig = {}, onComponentsRegistered = undefined) {
|
|
24
24
|
const siteStartPage = playbook.site.startPage
|
|
25
25
|
let contentCatalog = registerComponentVersions(new ContentCatalog(playbook), aggregate, siteAsciiDocConfig)
|
|
26
26
|
return typeof onComponentsRegistered === 'function' &&
|
|
@@ -156,13 +156,19 @@ function getNavInfo (filepath, nav) {
|
|
|
156
156
|
if (~index) return nav.resolved.add(filepath) && { index }
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
function resolveAsciiDocConfig (siteAsciiDocConfig, { asciidoc, origins = [] }) {
|
|
160
|
-
const scopedAttributes =
|
|
159
|
+
function resolveAsciiDocConfig (siteAsciiDocConfig, { name, version, asciidoc, origins = [] }) {
|
|
160
|
+
const scopedAttributes = asciidoc?.attributes
|
|
161
161
|
if (scopedAttributes) {
|
|
162
|
-
const initial = siteAsciiDocConfig.attributes
|
|
162
|
+
const initial = Object.assign({}, siteAsciiDocConfig.attributes)
|
|
163
|
+
initial['antora-component-name'] = name
|
|
164
|
+
initial['antora-component-version'] = version
|
|
163
165
|
const mdc = { file: { path: 'antora.yml', origin: origins[origins.length - 1] } }
|
|
164
166
|
const attributes = collateAsciiDocAttributes(scopedAttributes, { initial, mdc, merge: true })
|
|
165
|
-
if (attributes !== initial)
|
|
167
|
+
if (attributes !== initial) {
|
|
168
|
+
delete attributes['antora-component-name']
|
|
169
|
+
delete attributes['antora-component-version']
|
|
170
|
+
return Object.assign({}, siteAsciiDocConfig, { attributes })
|
|
171
|
+
}
|
|
166
172
|
}
|
|
167
173
|
return siteAsciiDocConfig
|
|
168
174
|
}
|
package/lib/content-catalog.js
CHANGED
|
@@ -87,10 +87,10 @@ class ContentCatalog {
|
|
|
87
87
|
let lastVerdict
|
|
88
88
|
const insertIdx = version
|
|
89
89
|
? componentVersions.findIndex(({ version: candidateVersion, prerelease: candidatePrerelease }) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
return (lastVerdict = versionCompare(candidateVersion, version)) > 1
|
|
91
|
+
? !!prerelease === !!candidatePrerelease
|
|
92
|
+
: lastVerdict > 0 || (lastVerdict < -1 && prerelease && !candidatePrerelease)
|
|
93
|
+
})
|
|
94
94
|
: prerelease
|
|
95
95
|
? -1
|
|
96
96
|
: ~(~componentVersions.findIndex(({ prerelease: candidatePrerelease }) => !candidatePrerelease) || -1)
|
|
@@ -147,16 +147,14 @@ class ContentCatalog {
|
|
|
147
147
|
if (filesForFamily.has(key)) {
|
|
148
148
|
if (family === 'alias') {
|
|
149
149
|
throw new Error(`Duplicate alias: ${generateResourceSpec(src)}`)
|
|
150
|
-
} else {
|
|
151
|
-
const details = [filesForFamily.get(key), file]
|
|
152
|
-
.map((it, idx) => `${idx + 1}: ${summarizeFileLocation(it)}`)
|
|
153
|
-
.join(LOG_WRAP)
|
|
154
|
-
if (family === 'nav') {
|
|
155
|
-
throw new Error(`Duplicate nav file: ${file.path} in ${version}@${component}${LOG_WRAP}${details}`)
|
|
156
|
-
} else {
|
|
157
|
-
throw new Error(`Duplicate ${family}: ${generateResourceSpec(src)}${LOG_WRAP}${details}`)
|
|
158
|
-
}
|
|
159
150
|
}
|
|
151
|
+
const details = [filesForFamily.get(key), file]
|
|
152
|
+
.map((it, idx) => `${idx + 1}: ${summarizeFileLocation(it)}`)
|
|
153
|
+
.join(LOG_WRAP)
|
|
154
|
+
if (family === 'nav') {
|
|
155
|
+
throw new Error(`Duplicate nav file: ${file.path} in ${version}@${component}${LOG_WRAP}${details}`)
|
|
156
|
+
}
|
|
157
|
+
throw new Error(`Duplicate ${family}: ${generateResourceSpec(src)}${LOG_WRAP}${details}`)
|
|
160
158
|
}
|
|
161
159
|
// NOTE: if the path property is not set, assume the src likely needs to be prepared
|
|
162
160
|
// another option is to assume that if the file is not a vinyl object, the src likely needs to be prepared
|
|
@@ -172,7 +170,7 @@ class ContentCatalog {
|
|
|
172
170
|
// NOTE: an alias masquerades as the target file
|
|
173
171
|
family = file.rel.src.family
|
|
174
172
|
// NOTE: short circuit in case of splat alias (alias -> alias)
|
|
175
|
-
if (family === 'alias' &&
|
|
173
|
+
if (family === 'alias' && file.pub?.splat) return filesForFamily.set(key, file) && file
|
|
176
174
|
src.mediaType = 'text/asciidoc'
|
|
177
175
|
} else if (!(file.mediaType = src.mediaType) && !('mediaType' in src)) {
|
|
178
176
|
// QUESTION: should we preserve the mediaType property on file if already defined?
|
|
@@ -243,7 +241,7 @@ class ContentCatalog {
|
|
|
243
241
|
}
|
|
244
242
|
|
|
245
243
|
getComponentVersion (component, version) {
|
|
246
|
-
return (component.versions ||
|
|
244
|
+
return (component.versions || this.getComponent(component)?.versions || []).find(
|
|
247
245
|
({ version: candidate }) => candidate === version
|
|
248
246
|
)
|
|
249
247
|
}
|
|
@@ -271,9 +269,8 @@ class ContentCatalog {
|
|
|
271
269
|
const accum = []
|
|
272
270
|
for (const candidate of candidates.values()) filter(candidate) && accum.push(candidate)
|
|
273
271
|
return accum
|
|
274
|
-
} else {
|
|
275
|
-
return [...candidates.values()]
|
|
276
272
|
}
|
|
273
|
+
return [...candidates.values()]
|
|
277
274
|
}
|
|
278
275
|
|
|
279
276
|
// TODO add `follow` argument to control whether alias is followed
|
|
@@ -370,7 +367,8 @@ class ContentCatalog {
|
|
|
370
367
|
if (rootIndexAlias) return rootIndexAlias.synthetic ? Object.assign(rootIndexAlias, { rel }) : undefined
|
|
371
368
|
const src = Object.assign({}, ROOT_INDEX_ALIAS_ID)
|
|
372
369
|
return this.addFile({ src, rel, synthetic: true }, { version: src.version })
|
|
373
|
-
}
|
|
370
|
+
}
|
|
371
|
+
if (rel === false) {
|
|
374
372
|
logger.warn('Start page specified for site has invalid syntax: %s', startPageSpec)
|
|
375
373
|
} else if (startPageSpec.lastIndexOf(':') > startPageSpec.indexOf(':')) {
|
|
376
374
|
logger.warn('Start page specified for site not found: %s', startPageSpec)
|
|
@@ -400,10 +398,10 @@ class ContentCatalog {
|
|
|
400
398
|
throw new Error(
|
|
401
399
|
existingPage === target
|
|
402
400
|
? `Page cannot define alias that references itself: ${generateResourceSpec(src)}` +
|
|
403
|
-
|
|
401
|
+
` (specified as: ${spec})${LOG_WRAP}source: ${summarizeFileLocation(existingPage)}`
|
|
404
402
|
: `Page alias cannot reference an existing page: ${generateResourceSpec(src)} (specified as: ${spec})` +
|
|
405
|
-
|
|
406
|
-
|
|
403
|
+
`${LOG_WRAP}source: ${summarizeFileLocation(target)}` +
|
|
404
|
+
`${LOG_WRAP}existing page: ${summarizeFileLocation(existingPage)}`
|
|
407
405
|
)
|
|
408
406
|
}
|
|
409
407
|
} else if (src.version == null) {
|
|
@@ -26,7 +26,6 @@ const parseResourceId = require('./parse-resource-id')
|
|
|
26
26
|
*/
|
|
27
27
|
function resolveResource (spec, catalog, ctx = {}, defaultFamily = undefined, permittedFamilies = undefined) {
|
|
28
28
|
const id = parseResourceId(spec, ctx, defaultFamily, permittedFamilies)
|
|
29
|
-
|
|
30
29
|
if (!id || !id.family) return false
|
|
31
30
|
if (id.version == null) {
|
|
32
31
|
const component = catalog.getComponent(id.component)
|
|
@@ -34,10 +33,9 @@ function resolveResource (spec, catalog, ctx = {}, defaultFamily = undefined, pe
|
|
|
34
33
|
id.version = component.latest.version
|
|
35
34
|
}
|
|
36
35
|
if (!id.module) id.module = 'ROOT'
|
|
37
|
-
|
|
38
36
|
return (
|
|
39
37
|
catalog.getById(id) ||
|
|
40
|
-
(id.family === 'page' ?
|
|
38
|
+
(id.family === 'page' ? catalog.getById(Object.assign({}, id, { family: 'alias' }))?.rel : undefined)
|
|
41
39
|
)
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -24,11 +24,8 @@ function versionCompareDesc (a, b) {
|
|
|
24
24
|
if (a && b) {
|
|
25
25
|
const semverA = resolveSemver(a)
|
|
26
26
|
const semverB = resolveSemver(b)
|
|
27
|
-
if (semverA)
|
|
28
|
-
|
|
29
|
-
} else {
|
|
30
|
-
return semverB ? -1 : -2 * a.localeCompare(b, 'en', { numeric: true })
|
|
31
|
-
}
|
|
27
|
+
if (semverA) return semverB ? -semverCompare(semverA, semverB) : 1
|
|
28
|
+
return semverB ? -1 : -2 * a.localeCompare(b, 'en', { numeric: true })
|
|
32
29
|
}
|
|
33
30
|
return a ? 1 : -1
|
|
34
31
|
}
|
|
@@ -64,23 +61,18 @@ function semverCompare (a, b) {
|
|
|
64
61
|
const numsA = a.split('.')
|
|
65
62
|
const numsB = b.split('.')
|
|
66
63
|
for (let i = 0; i < 3; i++) {
|
|
67
|
-
const numA = Number(numsA[i]
|
|
68
|
-
const numB = Number(numsB[i]
|
|
69
|
-
if (numA > numB)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return -1
|
|
73
|
-
} else if (isNaN(
|
|
74
|
-
if (!isNaN(numB)) return -1
|
|
75
|
-
} else if (isNaN(numB)) {
|
|
64
|
+
const numA = Number(numsA[i] ?? 0)
|
|
65
|
+
const numB = Number(numsB[i] ?? 0)
|
|
66
|
+
if (numA > numB) return 1
|
|
67
|
+
if (numB > numA) return -1
|
|
68
|
+
if (Number.isNaN(numA)) {
|
|
69
|
+
if (!Number.isNaN(numB)) return -1
|
|
70
|
+
} else if (Number.isNaN(numB)) {
|
|
76
71
|
return 1
|
|
77
72
|
}
|
|
78
73
|
}
|
|
79
|
-
if (preA == null)
|
|
80
|
-
|
|
81
|
-
} else {
|
|
82
|
-
return preB == null ? -1 : preA.localeCompare(preB, 'en', { numeric: true })
|
|
83
|
-
}
|
|
74
|
+
if (preA == null) return preB == null ? 0 : 1
|
|
75
|
+
return preB == null ? -1 : preA.localeCompare(preB, 'en', { numeric: true })
|
|
84
76
|
}
|
|
85
77
|
|
|
86
78
|
module.exports = versionCompareDesc
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/content-classifier",
|
|
3
|
-
"version": "3.2.0-alpha.
|
|
3
|
+
"version": "3.2.0-alpha.8",
|
|
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)",
|
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
"Hubert SABLONNIÈRE <hubert.sablonniere@gmail.com>"
|
|
11
11
|
],
|
|
12
12
|
"homepage": "https://antora.org",
|
|
13
|
-
"repository":
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://gitlab.com/antora/antora.git",
|
|
16
|
+
"directory": "packages/content-classifier"
|
|
17
|
+
},
|
|
14
18
|
"bugs": {
|
|
15
19
|
"url": "https://gitlab.com/antora/antora/issues"
|
|
16
20
|
},
|
|
@@ -27,8 +31,8 @@
|
|
|
27
31
|
"#constants": "./lib/constants.js"
|
|
28
32
|
},
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@antora/asciidoc-loader": "3.2.0-alpha.
|
|
31
|
-
"@antora/logger": "3.2.0-alpha.
|
|
34
|
+
"@antora/asciidoc-loader": "3.2.0-alpha.8",
|
|
35
|
+
"@antora/logger": "3.2.0-alpha.8",
|
|
32
36
|
"mime-types": "~2.1",
|
|
33
37
|
"vinyl": "~3.0"
|
|
34
38
|
},
|