@antora/content-classifier
Advanced tools
Comparing version 3.2.0-alpha.1 to 3.2.0-alpha.2
@@ -11,38 +11,54 @@ 'use strict' | ||
* | ||
* @param {Object} playbook - The configuration object for Antora. | ||
* @param {Object} playbook - The configuration object for Antora. See ContentCatalog constructor for relevant keys. | ||
* @param {Object} playbook.site - Site-related configuration data. | ||
* @param {String} playbook.site.startPage - The start page for the site; redirects from base URL. | ||
* @param {Object} playbook.urls - URL settings for the site. | ||
* @param {String} playbook.urls.htmlExtensionStyle - The style to use when computing page URLs. | ||
* @param {Object} aggregate - The raw aggregate of virtual file objects to be classified. | ||
* @param {Object} [siteAsciiDocConfig={}] - Site-wide AsciiDoc processor configuration options. | ||
* @returns {ContentCatalog} A structured catalog of content components and virtual content files. | ||
* @param {Function} [onComponentsRegistered] - A function (optionally async) to invoke after components are | ||
* registered. Must return an instance of ContentCatalog. If async, this function will also return a Promise. | ||
* | ||
* @returns {ContentCatalog} A structured catalog of content components, versions, and virtual content files. | ||
*/ | ||
function classifyContent (playbook, aggregate, siteAsciiDocConfig = {}) { | ||
const contentCatalog = new ContentCatalog(playbook) | ||
aggregate | ||
.reduce((accum, componentVersionData) => { | ||
// drop files since they aren't needed to register component version | ||
// drop startPage to defer registration of start page | ||
const { name, version, files, startPage, ...descriptor } = Object.assign({}, componentVersionData, { | ||
asciidoc: resolveAsciiDocConfig(siteAsciiDocConfig, componentVersionData), | ||
}) | ||
return new Map(accum).set( | ||
contentCatalog.registerComponentVersion(name, version, descriptor), | ||
componentVersionData | ||
) | ||
}, new Map()) | ||
.forEach((componentVersionData, componentVersion) => { | ||
const { name, version } = componentVersion | ||
const { files, nav, startPage } = componentVersionData | ||
componentVersionData.files = undefined // clean up memory | ||
files.forEach((file) => allocateSrc(file, name, version, nav) && contentCatalog.addFile(file, componentVersion)) | ||
contentCatalog.registerComponentVersionStartPage(name, componentVersion, startPage) | ||
function classifyContent (playbook, aggregate, siteAsciiDocConfig = {}, onComponentsRegistered) { | ||
const siteStartPage = playbook.site.startPage | ||
let contentCatalog = registerComponentVersions(new ContentCatalog(playbook), aggregate, siteAsciiDocConfig) | ||
return typeof onComponentsRegistered === 'function' && | ||
(contentCatalog = onComponentsRegistered(contentCatalog)) instanceof Promise | ||
? contentCatalog.then((contentCatalogValue) => addFilesAndRegisterStartPages(contentCatalogValue, siteStartPage)) | ||
: addFilesAndRegisterStartPages(contentCatalog, siteStartPage) | ||
} | ||
function registerComponentVersions (contentCatalog, aggregate, siteAsciiDocConfig) { | ||
for (const componentVersionBucket of aggregate) { | ||
// advance files, nav, and startPage to component version to be used in later phase | ||
const { name, version, files, nav, startPage, ...data } = Object.assign(componentVersionBucket, { | ||
asciidoc: resolveAsciiDocConfig(siteAsciiDocConfig, componentVersionBucket), | ||
}) | ||
contentCatalog.registerSiteStartPage(playbook.site.startPage) | ||
Object.assign(contentCatalog.registerComponentVersion(name, version, data), { files, nav, startPage }) | ||
} | ||
return contentCatalog | ||
} | ||
function addFilesAndRegisterStartPages (contentCatalog, siteStartPage) { | ||
for (const { versions: componentVersions } of contentCatalog.getComponents()) { | ||
for (const componentVersion of componentVersions) { | ||
const { name: component, version, files = [], nav, startPage } = componentVersion | ||
for (let file, i = 0, len = files.length; i < len; i++) { | ||
allocateSrc((file = files[i]), component, version, nav) && contentCatalog.addFile(file, componentVersion) | ||
files[i] = undefined // free memory | ||
} | ||
contentCatalog.registerComponentVersionStartPage(component, componentVersion, startPage) | ||
} | ||
} | ||
contentCatalog.registerSiteStartPage(siteStartPage) | ||
return contentCatalog | ||
} | ||
function allocateSrc (file, component, version, nav) { | ||
const extname = file.src.extname | ||
const { extname, family } = file.src | ||
if (family && family !== 'nav') { | ||
Object.assign(file.src, { component, version }) | ||
file.src.moduleRootPath ??= calculateRootPath(file.src.relative.split('/').length) | ||
return true | ||
} | ||
const filepath = file.path | ||
@@ -49,0 +65,0 @@ const navInfo = nav && getNavInfo(filepath, nav) |
@@ -45,2 +45,4 @@ 'use strict' | ||
* | ||
* Must be followed by a call to registerComponentVersionStartPage to finalize object. | ||
* | ||
* @param {String} name - The name of the component to which this component version belongs. | ||
@@ -278,3 +280,11 @@ * @param {String} version - The version of the component to register. | ||
getSiteStartPage () { | ||
return this.getById(ROOT_INDEX_PAGE_ID) || (this.getById(ROOT_INDEX_ALIAS_ID) || {}).rel | ||
let file | ||
if ((file = this.getById(ROOT_INDEX_PAGE_ID))) return file | ||
if ((file = this.getById(ROOT_INDEX_ALIAS_ID))) return file.rel | ||
const rootComponent = this.getComponent('ROOT') | ||
if (!rootComponent) return | ||
const version = rootComponent.versions.find(({ activeVersionSegment }) => activeVersionSegment === '')?.version | ||
if (!version) return | ||
if ((file = this.getById(Object.assign({}, ROOT_INDEX_PAGE_ID, { version })))) return file | ||
if ((file = this.getById(Object.assign({}, ROOT_INDEX_ALIAS_ID, { version })))) return file.rel | ||
} | ||
@@ -323,3 +333,3 @@ | ||
componentVersion.url = startPage.pub.url | ||
} else { | ||
} else if (!componentVersion.url) { | ||
// QUESTION: should we warn if the default start page cannot be found? | ||
@@ -334,17 +344,20 @@ componentVersion.url = computePub( | ||
} | ||
Object.defineProperty( | ||
componentVersion, | ||
'activeVersionSegment', | ||
activeVersionSegment === version | ||
? { | ||
configurable: true, | ||
get () { | ||
return this.version | ||
}, | ||
} | ||
: { configurable: true, value: activeVersionSegment } | ||
) | ||
Object.defineProperties(componentVersion, { | ||
activeVersionSegment: | ||
activeVersionSegment === version | ||
? { configurable: true, enumerable: false, get: getVersion } | ||
: { configurable: true, enumerable: false, value: activeVersionSegment }, | ||
files: { | ||
configurable: true, | ||
enumerable: false, | ||
get: getComponentVersionFiles.bind(this, { component, version }), | ||
}, | ||
startPage: { | ||
configurable: true, | ||
enumerable: false, | ||
get: getComponentVersionStartPage.bind(this, { component, version }), | ||
}, | ||
}) | ||
addSymbolicVersionAlias.call(this, componentVersion) | ||
return startPage | ||
} | ||
@@ -357,4 +370,5 @@ | ||
if (this.getById(ROOT_INDEX_PAGE_ID)) return | ||
const indexAlias = this.getById(ROOT_INDEX_ALIAS_ID) | ||
if (indexAlias) return indexAlias.synthetic ? Object.assign(indexAlias, { rel }) : undefined | ||
if (rel.pub.url === (this.htmlUrlExtensionStyle === 'default' ? '/index.html' : '/')) return | ||
const rootIndexAlias = this.getById(ROOT_INDEX_ALIAS_ID) | ||
if (rootIndexAlias) return rootIndexAlias.synthetic ? Object.assign(rootIndexAlias, { rel }) : undefined | ||
const src = Object.assign({}, ROOT_INDEX_ALIAS_ID) | ||
@@ -634,2 +648,14 @@ return this.addFile({ src, rel, synthetic: true }, { version: src.version }) | ||
function getComponentVersionFiles (componentVersionId) { | ||
return this.findBy(componentVersionId) | ||
} | ||
function getComponentVersionStartPage (componentVersionId) { | ||
return this.resolvePage('index.adoc', componentVersionId) | ||
} | ||
function getVersion () { | ||
return this.version | ||
} | ||
module.exports = ContentCatalog |
{ | ||
"name": "@antora/content-classifier", | ||
"version": "3.2.0-alpha.1", | ||
"version": "3.2.0-alpha.2", | ||
"description": "Organizes aggregated content into a virtual file catalog for use in an Antora documentation pipeline.", | ||
@@ -30,4 +30,4 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/asciidoc-loader": "3.2.0-alpha.1", | ||
"@antora/logger": "3.2.0-alpha.1", | ||
"@antora/asciidoc-loader": "3.2.0-alpha.2", | ||
"@antora/logger": "3.2.0-alpha.2", | ||
"mime-types": "~2.1", | ||
@@ -34,0 +34,0 @@ "vinyl": "~2.2" |
@@ -12,2 +12,2 @@ # Antora Content Classifier | ||
Use of this software is granted under the terms of the [Mozilla Public License Version 2.0](https://www.mozilla.org/en-US/MPL/2.0/) (MPL-2.0). | ||
Use of this software is granted under the terms of the [Mozilla Public License Version 2.0](https://www.mozilla.org/en-US/MPL/2.0/) (MPL-2.0). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46125
992
12
+ Added@antora/asciidoc-loader@3.2.0-alpha.2(transitive)
+ Added@antora/logger@3.2.0-alpha.2(transitive)
- Removed@antora/asciidoc-loader@3.2.0-alpha.1(transitive)
- Removed@antora/logger@3.2.0-alpha.1(transitive)
Updated@antora/logger@3.2.0-alpha.2