@antora/content-classifier 3.2.0-alpha.8 → 3.2.0-alpha.9
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/content-catalog.js +64 -37
- package/package.json +3 -3
package/lib/content-catalog.js
CHANGED
|
@@ -11,7 +11,6 @@ const summarizeFileLocation = require('./util/summarize-file-location')
|
|
|
11
11
|
const versionCompare = require('./util/version-compare-desc')
|
|
12
12
|
|
|
13
13
|
const { ROOT_INDEX_ALIAS_ID, ROOT_INDEX_PAGE_ID } = require('./constants')
|
|
14
|
-
const SPACE_RX = / /g
|
|
15
14
|
const LOG_WRAP = '\n '
|
|
16
15
|
|
|
17
16
|
const $components = Symbol('components')
|
|
@@ -61,8 +60,13 @@ class ContentCatalog {
|
|
|
61
60
|
* @returns {Object} The constructed component version object.
|
|
62
61
|
*/
|
|
63
62
|
registerComponentVersion (name, version, descriptor = {}) {
|
|
64
|
-
const { asciidoc, displayVersion, prerelease, startPage:
|
|
65
|
-
const componentVersion = {
|
|
63
|
+
const { asciidoc, displayVersion, prerelease, startPage: startPageRef, title, versionSegment, origins } = descriptor
|
|
64
|
+
const componentVersion = {
|
|
65
|
+
displayVersion: displayVersion || version || 'default',
|
|
66
|
+
title: title || name,
|
|
67
|
+
version,
|
|
68
|
+
origins: new Set(origins && typeof origins[Symbol.iterator] === 'function' ? origins : []),
|
|
69
|
+
}
|
|
66
70
|
if (versionSegment != null) componentVersion.versionSegment = versionSegment
|
|
67
71
|
Object.defineProperty(componentVersion, 'name', { value: name, enumerable: true })
|
|
68
72
|
if (prerelease) {
|
|
@@ -131,9 +135,9 @@ class ContentCatalog {
|
|
|
131
135
|
)
|
|
132
136
|
)
|
|
133
137
|
}
|
|
134
|
-
if (
|
|
138
|
+
if (startPageRef) {
|
|
135
139
|
// @deprecated use separate call to register start page for component version
|
|
136
|
-
this.registerComponentVersionStartPage(name, componentVersion,
|
|
140
|
+
this.registerComponentVersionStartPage(name, componentVersion, startPageRef === true ? undefined : startPageRef)
|
|
137
141
|
}
|
|
138
142
|
return componentVersion
|
|
139
143
|
}
|
|
@@ -156,11 +160,9 @@ class ContentCatalog {
|
|
|
156
160
|
}
|
|
157
161
|
throw new Error(`Duplicate ${family}: ${generateResourceSpec(src)}${LOG_WRAP}${details}`)
|
|
158
162
|
}
|
|
159
|
-
// NOTE: if the
|
|
160
|
-
// another option is to assume that if the file is not a vinyl object, the src likely needs to be prepared
|
|
163
|
+
// NOTE: assume that if the file is not a vinyl object, the src likely needs to be prepared
|
|
161
164
|
// a vinyl object is one indication the file was created and prepared by the content aggregator
|
|
162
|
-
//if
|
|
163
|
-
//if (!File.isVinyl(file)) file = new File(file)
|
|
165
|
+
// an alternate approach would be to call prepareSrc if the path property is not set
|
|
164
166
|
if (!File.isVinyl(file)) {
|
|
165
167
|
prepareSrc(src)
|
|
166
168
|
file = new File(file)
|
|
@@ -183,18 +185,25 @@ class ContentCatalog {
|
|
|
183
185
|
} else if ('out' in file) {
|
|
184
186
|
delete file.out
|
|
185
187
|
} else if (
|
|
188
|
+
!file.private &&
|
|
186
189
|
(family === 'page' || family === 'image' || family === 'attachment') &&
|
|
187
|
-
('/' + src.relative).indexOf('/_') < 0
|
|
190
|
+
(file.private === false || ('/' + src.relative).indexOf('/_') < 0)
|
|
188
191
|
) {
|
|
189
192
|
publishable = true
|
|
190
193
|
if (componentVersion == null) componentVersion = this.getComponentVersion(component, version) || { version }
|
|
191
|
-
activeVersionSegment =
|
|
194
|
+
activeVersionSegment =
|
|
195
|
+
'activeVersionSegment' in componentVersion
|
|
196
|
+
? componentVersion.activeVersionSegment
|
|
197
|
+
: computeVersionSegment.call(this, componentVersion)
|
|
192
198
|
file.out = computeOut(src, family, activeVersionSegment, this.htmlUrlExtensionStyle)
|
|
193
199
|
}
|
|
194
200
|
if (!file.pub && (publishable || family === 'nav')) {
|
|
195
201
|
if (activeVersionSegment == null) {
|
|
196
202
|
if (componentVersion == null) componentVersion = this.getComponentVersion(component, version) || { version }
|
|
197
|
-
activeVersionSegment =
|
|
203
|
+
activeVersionSegment =
|
|
204
|
+
'activeVersionSegment' in componentVersion
|
|
205
|
+
? componentVersion.activeVersionSegment
|
|
206
|
+
: computeVersionSegment.call(this, componentVersion)
|
|
198
207
|
}
|
|
199
208
|
file.pub = computePub(src, file.out, family, activeVersionSegment, this.htmlUrlExtensionStyle)
|
|
200
209
|
}
|
|
@@ -446,26 +455,48 @@ class ContentCatalog {
|
|
|
446
455
|
}
|
|
447
456
|
|
|
448
457
|
/**
|
|
449
|
-
* Attempts to resolve a
|
|
458
|
+
* Attempts to resolve a page reference within the given context to a page in the catalog.
|
|
459
|
+
*
|
|
460
|
+
* Parses the specified page reference (i.e., page ID spec) into a partial page ID, expands it
|
|
461
|
+
* using the provided context, then attempts to locate a file in the page family with that page ID
|
|
462
|
+
* in this catalog. The family segment is optional.
|
|
450
463
|
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
* function returns undefined. If the spec does not match the page ID syntax, this function throws
|
|
456
|
-
* an error.
|
|
464
|
+
* If a component is specified, but no version, the latest version of the component stored in the
|
|
465
|
+
* catalog is used. If a page cannot be resolved, the search is attempted again for an "alias". If
|
|
466
|
+
* neither a page or alias can be resolved, the function returns undefined. If the syntax of the
|
|
467
|
+
* reference is invalid, this function throws an error.
|
|
457
468
|
*
|
|
458
|
-
* @param {String} spec - The contextual page
|
|
459
|
-
* @param {
|
|
460
|
-
* @param {Object} [ctx={}] - The context to use to qualified the contextual page ID.
|
|
469
|
+
* @param {String} spec - The contextual page reference (e.g., version@component:module:topic/page.adoc).
|
|
470
|
+
* @param {Object} [context={}] - The context to use to qualify the page reference.
|
|
461
471
|
*
|
|
462
|
-
* @returns {File} The virtual file to which the contextual page
|
|
463
|
-
* file cannot be resolved.
|
|
472
|
+
* @returns {File} The virtual file to which the contextual page reference resolves, or undefined
|
|
473
|
+
* if the file cannot be resolved.
|
|
464
474
|
*/
|
|
465
475
|
resolvePage (spec, context = {}) {
|
|
466
476
|
return this.resolveResource(spec, context, 'page', ['page'])
|
|
467
477
|
}
|
|
468
478
|
|
|
479
|
+
/**
|
|
480
|
+
* Attempts to resolve a resource reference within the given context to a file in the catalog.
|
|
481
|
+
*
|
|
482
|
+
* Parses the specified resource reference (i.e., resource ID spec) into a partial resource ID,
|
|
483
|
+
* expands it using the provided context, then attempts to locate a file with that resource ID in
|
|
484
|
+
* this catalog.
|
|
485
|
+
*
|
|
486
|
+
* If a component is specified, but no version, the latest version of the component stored in the
|
|
487
|
+
* catalog is used. If a defaultFamily is not specified, the family must be specified either by
|
|
488
|
+
* the reference or the context. If permittedFamilies are stated, the family must resolve to a
|
|
489
|
+
* family in this list. If a file cannot be resolved, the function returns undefined. If the
|
|
490
|
+
* syntax of the reference is invalid, this function throws an error.
|
|
491
|
+
*
|
|
492
|
+
* @param {String} spec - The contextual resource reference (e.g., version@component:module:image$topic/image.png).
|
|
493
|
+
* @param {Object} [context={}] - The context to use to qualify the resource reference.
|
|
494
|
+
* @param {String} [defaultFamily=undefined] - The default family to use if one is not provided.
|
|
495
|
+
* @param {Array<String>} [permittedFamilies=undefined] - A list of families that are permitted.
|
|
496
|
+
*
|
|
497
|
+
* @returns {File} The virtual file to which the contextual resource reference resolves, or
|
|
498
|
+
* undefined if the file cannot be resolved.
|
|
499
|
+
*/
|
|
469
500
|
resolveResource (spec, context = {}, defaultFamily = undefined, permittedFamilies = undefined) {
|
|
470
501
|
return resolveResource(spec, this, context, defaultFamily, permittedFamilies)
|
|
471
502
|
}
|
|
@@ -507,29 +538,25 @@ function generateResourceSpec ({ component, version, module: module_, family, re
|
|
|
507
538
|
|
|
508
539
|
function prepareSrc (src) {
|
|
509
540
|
let { basename, extname, stem } = src
|
|
510
|
-
let update
|
|
511
541
|
if (basename == null) {
|
|
512
|
-
|
|
513
|
-
basename = path.basename(src.relative)
|
|
542
|
+
basename = src.basename = path.basename(src.relative)
|
|
514
543
|
}
|
|
515
544
|
if (stem == null) {
|
|
516
|
-
update = true
|
|
517
545
|
if (extname == null) {
|
|
518
546
|
if (~(extname = basename.lastIndexOf('.'))) {
|
|
519
|
-
stem = basename.substr(0, extname)
|
|
520
|
-
extname = basename.substr(extname)
|
|
547
|
+
src.stem = basename.substr(0, extname)
|
|
548
|
+
src.extname = basename.substr(extname)
|
|
521
549
|
} else {
|
|
522
|
-
stem = basename
|
|
523
|
-
extname = ''
|
|
550
|
+
src.stem = basename
|
|
551
|
+
src.extname = ''
|
|
524
552
|
}
|
|
525
553
|
} else {
|
|
526
|
-
stem = basename.substr(0, basename.length - extname.length)
|
|
554
|
+
src.stem = basename.substr(0, basename.length - extname.length)
|
|
527
555
|
}
|
|
528
556
|
} else if (extname == null) {
|
|
529
|
-
|
|
530
|
-
extname = basename.substr(stem.length)
|
|
557
|
+
src.extname = basename.substr(stem.length)
|
|
531
558
|
}
|
|
532
|
-
return
|
|
559
|
+
return src
|
|
533
560
|
}
|
|
534
561
|
|
|
535
562
|
function computeOut (src, family, versionSegment, htmlUrlExtensionStyle) {
|
|
@@ -589,7 +616,7 @@ function computePub (src, out, family, versionSegment, htmlUrlExtensionStyle) {
|
|
|
589
616
|
} else if ((url = '/' + out.path) === '/.') {
|
|
590
617
|
url = '/'
|
|
591
618
|
}
|
|
592
|
-
pub.url = ~url.indexOf(' ') ? url.
|
|
619
|
+
pub.url = ~url.indexOf(' ') ? url.replaceAll(' ', '%20') : url
|
|
593
620
|
return out ? Object.assign(pub, { moduleRootPath: out.moduleRootPath, rootPath: out.rootPath }) : pub
|
|
594
621
|
}
|
|
595
622
|
|
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.9",
|
|
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)",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"#constants": "./lib/constants.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@antora/asciidoc-loader": "3.2.0-alpha.
|
|
35
|
-
"@antora/logger": "3.2.0-alpha.
|
|
34
|
+
"@antora/asciidoc-loader": "3.2.0-alpha.9",
|
|
35
|
+
"@antora/logger": "3.2.0-alpha.9",
|
|
36
36
|
"mime-types": "~2.1",
|
|
37
37
|
"vinyl": "~3.0"
|
|
38
38
|
},
|