@antora/content-classifier
Advanced tools
Comparing version 2.3.0-beta.1 to 2.3.0-beta.2
@@ -5,4 +5,2 @@ 'use strict' | ||
const { START_PAGE_ID } = require('./constants') | ||
/** | ||
@@ -23,2 +21,3 @@ * Organizes the raw aggregate of virtual files into a {ContentCatalog}. | ||
function classifyContent (playbook, aggregate, siteAsciiDocConfig = undefined) { | ||
// deprecated; remove fallback in Antora 3.x | ||
if (!siteAsciiDocConfig) siteAsciiDocConfig = require('@antora/asciidoc-loader').resolveConfig(playbook) | ||
@@ -33,3 +32,3 @@ const contentCatalog = aggregate.reduce((catalog, descriptor) => { | ||
}, new ContentCatalog(playbook)) | ||
registerSiteStartPage(playbook, contentCatalog) | ||
contentCatalog.registerSiteStartPage(playbook.site.startPage) | ||
return contentCatalog | ||
@@ -103,3 +102,2 @@ } | ||
} | ||
file.src.component = component | ||
@@ -124,20 +122,2 @@ file.src.version = version | ||
function registerSiteStartPage (playbook, contentCatalog) { | ||
const pageSpec = playbook.site.startPage | ||
if (!pageSpec) return | ||
const rel = contentCatalog.resolvePage(pageSpec) | ||
if (rel) { | ||
const src = Object.assign({}, START_PAGE_ID, { | ||
family: 'alias', | ||
basename: 'index.adoc', | ||
stem: 'index', | ||
mediaType: 'text/asciidoc', | ||
}) | ||
contentCatalog.addFile({ src, rel }) | ||
} else { | ||
console.warn('Start page specified for site not found: ' + pageSpec) | ||
//throw new Error('Start page specified for site not found: ' + pageSpec) | ||
} | ||
} | ||
function resolveAsciiDocConfig (siteAsciiDocConfig, { asciidoc }) { | ||
@@ -144,0 +124,0 @@ const scopedAttributes = (asciidoc || {}).attributes |
'use strict' | ||
module.exports = Object.freeze({ | ||
START_ALIAS_ID: Object.freeze({ component: '', version: '', module: '', family: 'alias', relative: 'index.adoc' }), | ||
START_PAGE_ID: Object.freeze({ component: '', version: '', module: '', family: 'page', relative: 'index.adoc' }), | ||
}) |
@@ -9,3 +9,3 @@ 'use strict' | ||
const { START_PAGE_ID } = require('./constants') | ||
const { START_ALIAS_ID, START_PAGE_ID } = require('./constants') | ||
const SPACE_RX = / /g | ||
@@ -26,18 +26,31 @@ | ||
const { asciidoc, displayVersion, prerelease, title, startPage: startPageSpec } = descriptor | ||
let startPage = this.resolvePage(startPageSpec || 'index.adoc', { component: name, version, module: 'ROOT' }) | ||
if (!startPage) { | ||
//if (startPageSpec) throw new Error(`Start page specified for ${version}@${name} not found: ` + startPageSpec) | ||
if (startPageSpec) console.warn(`Start page specified for ${version}@${name} not found: ` + startPageSpec) | ||
// TODO throw error or report warning; for now, we're just faking it | ||
//throw new Error(`Start page for ${version}@${name} not specified and no index page found.`) | ||
const startPageSrc = expandPageSrc({ component: name, version, module: 'ROOT', relative: 'index.adoc' }) | ||
const startPageOut = computeOut(startPageSrc, startPageSrc.family, this.htmlUrlExtensionStyle) | ||
const startPagePub = computePub(startPageSrc, startPageOut, startPageSrc.family, this.htmlUrlExtensionStyle) | ||
startPage = { pub: startPagePub } | ||
const componentVersion = { displayVersion: displayVersion || version, title: title || name, version } | ||
Object.defineProperty(componentVersion, 'name', { value: name, enumerable: true }) | ||
let startPage | ||
const indexPageId = { component: name, version, module: 'ROOT', family: 'page', relative: 'index.adoc' } | ||
if (startPageSpec) { | ||
const formalStartPageSpec = startPageSpec.endsWith('.adoc') ? startPageSpec : `${startPageSpec}.adoc` | ||
const { src: startPageSrc } = (startPage = this.resolvePage(formalStartPageSpec, indexPageId)) || {} | ||
if (startPageSrc && startPageSrc.component === name && startPageSrc.version === version) { | ||
if (!(startPageSrc.module === 'ROOT' && startPageSrc.relative === 'index.adoc')) { | ||
this.addFile({ mediaType: 'text/html', src: inflateSrc(indexPageId, 'alias'), rel: startPage }) | ||
} | ||
} else { | ||
startPage = this.getById(indexPageId) | ||
console.warn(`Start page specified for ${version}@${name} not found: ${formalStartPageSpec}`) | ||
} | ||
} else { | ||
startPage = this.getById(indexPageId) | ||
} | ||
const componentVersion = { | ||
displayVersion: displayVersion || version, | ||
title: title || name, | ||
url: startPage.pub.url, | ||
version, | ||
if (startPage) { | ||
componentVersion.url = startPage.pub.url | ||
} else { | ||
// QUESTION: should we warn if the default start page cannot be found? | ||
const startPageSrc = inflateSrc(indexPageId) | ||
componentVersion.url = computePub( | ||
startPageSrc, | ||
computeOut(startPageSrc, startPageSrc.family, this.htmlUrlExtensionStyle), | ||
startPageSrc.family, | ||
this.htmlUrlExtensionStyle | ||
).url | ||
} | ||
@@ -73,9 +86,9 @@ if (prerelease) { | ||
asciidoc: { | ||
get: function () { | ||
get () { | ||
return this.latest.asciidoc | ||
}, | ||
}, | ||
// NOTE alias latestVersion to latest for backwards compatibility | ||
// NOTE deprecated; alias latestVersion to latest for backwards compatibility; remove in Antora 3 | ||
latestVersion: { | ||
get: function () { | ||
get () { | ||
return this.latest | ||
@@ -85,3 +98,3 @@ }, | ||
title: { | ||
get: function () { | ||
get () { | ||
return this.latest.title | ||
@@ -91,3 +104,3 @@ }, | ||
url: { | ||
get: function () { | ||
get () { | ||
return this.latest.url | ||
@@ -103,3 +116,2 @@ }, | ||
// QUESTION should this method return the file added? | ||
addFile (file) { | ||
@@ -204,9 +216,19 @@ const key = generateKey(file.src) | ||
getSiteStartPage () { | ||
const page = this.getById(START_PAGE_ID) || this.getById(Object.assign({}, START_PAGE_ID, { family: 'alias' })) | ||
if (page) return page.src.family === 'alias' ? page.rel : page | ||
return this.getById(START_PAGE_ID) || (this.getById(START_ALIAS_ID) || {}).rel | ||
} | ||
registerSiteStartPage (startPageSpec) { | ||
if (!startPageSpec) return | ||
const formalStartPageSpec = startPageSpec.endsWith('.adoc') ? startPageSpec : `${startPageSpec}.adoc` | ||
const rel = this.resolvePage(formalStartPageSpec) | ||
if (rel) { | ||
return this.addFile({ mediaType: 'text/html', src: inflateSrc(Object.assign({}, START_ALIAS_ID), 'alias'), rel }) | ||
} else { | ||
console.warn(`Start page specified for site not found: ${formalStartPageSpec}`) | ||
} | ||
} | ||
// QUESTION should this be addPageAlias? | ||
registerPageAlias (aliasSpec, targetPage) { | ||
const src = parseResourceId(aliasSpec, targetPage.src, 'page', ['page']) | ||
registerPageAlias (spec, rel) { | ||
const src = parseResourceId(spec, rel.src, 'page', ['page']) | ||
// QUESTION should we throw an error if alias is invalid? | ||
@@ -223,3 +245,3 @@ if (!src) return | ||
qualifiedSpec = qualifiedSpec.replace(':page$', ':') | ||
const message = `Page alias cannot reference ${targetPage === existingPage ? 'itself' : 'an existing page'}` | ||
const message = `Page alias cannot reference ${existingPage === rel ? 'itself' : 'an existing page'}` | ||
throw new Error(message + ': ' + qualifiedSpec) | ||
@@ -231,10 +253,7 @@ } | ||
} | ||
expandPageSrc(src, 'alias') | ||
// QUESTION should we use src.origin instead of rel with type='link'? | ||
//src.origin = { type: 'link', target: targetPage } | ||
//src.origin = { type: 'link', target: rel } | ||
// NOTE the redirect producer will populate contents when the redirect facility is 'static' | ||
// QUESTION should we set the path property on the alias file? | ||
const file = new File({ path: targetPage.path, mediaType: src.mediaType, src, rel: targetPage }) | ||
this.addFile(file) | ||
return file | ||
//const path_ = path.join(targetPage.path.slice(0, -targetPage.src.relative.length), src.relative) | ||
return this.addFile({ mediaType: 'text/html', src: inflateSrc(src, 'alias'), rel }) | ||
} | ||
@@ -318,8 +337,14 @@ | ||
function expandPageSrc (src, family = 'page') { | ||
function inflateSrc (src, family = 'page', mediaType = 'text/asciidoc') { | ||
const basename = (src.basename = path.basename(src.relative)) | ||
const extIdx = basename.lastIndexOf('.') | ||
if (~extIdx) { | ||
src.stem = basename.substr(0, extIdx) | ||
src.extname = basename.substr(extIdx) | ||
} else { | ||
src.stem = basename | ||
src.extname = '' | ||
} | ||
src.family = family | ||
src.basename = path.basename(src.relative) | ||
src.extname = path.extname(src.relative) | ||
src.stem = path.basename(src.relative, src.extname) | ||
src.mediaType = 'text/asciidoc' | ||
src.mediaType = mediaType | ||
return src | ||
@@ -333,4 +358,6 @@ } | ||
const stem = src.stem | ||
let basename = src.mediaType === 'text/asciidoc' ? stem + '.html' : src.basename | ||
let basename = src.basename || path.basename(src.relative) | ||
const stem = src.stem || basename.substr(0, ((basename.lastIndexOf('.') + 1) || basename.length + 1) - 1) | ||
if (src.mediaType === 'text/asciidoc') basename = stem + '.html' | ||
let indexifyPathSegment = '' | ||
@@ -355,9 +382,3 @@ if (family === 'page' && stem !== 'index' && htmlUrlExtensionStyle === 'indexify') { | ||
return { | ||
dirname, | ||
basename, | ||
path: path_, | ||
moduleRootPath, | ||
rootPath, | ||
} | ||
return { dirname, basename, path: path_, moduleRootPath, rootPath } | ||
} | ||
@@ -364,0 +385,0 @@ |
@@ -35,3 +35,16 @@ 'use strict' | ||
let version = match[RESOURCE_ID_RX_GROUP.version] | ||
let component = match[RESOURCE_ID_RX_GROUP.component] | ||
let module = match[RESOURCE_ID_RX_GROUP.module] | ||
let family = match[RESOURCE_ID_RX_GROUP.family] | ||
let relative = match[RESOURCE_ID_RX_GROUP.relative] | ||
if (component) { | ||
if (!module) module = 'ROOT' | ||
} else { | ||
component = ctx.component | ||
if (!version) version = ctx.version | ||
if (!module) module = ctx.module | ||
} | ||
if (family) { | ||
@@ -43,6 +56,2 @@ if (permittedFamilies && !permittedFamilies.includes(family)) family = undefined | ||
let version = match[RESOURCE_ID_RX_GROUP.version] | ||
let component = match[RESOURCE_ID_RX_GROUP.component] | ||
let module = match[RESOURCE_ID_RX_GROUP.module] | ||
let relative = match[RESOURCE_ID_RX_GROUP.relative] | ||
if (~relative.indexOf('/')) { | ||
@@ -54,12 +63,3 @@ relative = relative | ||
} | ||
if ((family === 'page' || family === 'alias') && !relative.endsWith('.adoc')) relative += '.adoc' | ||
if (component) { | ||
if (!module) module = 'ROOT' | ||
} else { | ||
component = ctx.component | ||
if (!version) version = ctx.version | ||
if (!module) module = ctx.module | ||
} | ||
return { component, version, module, family, relative } | ||
@@ -66,0 +66,0 @@ } |
{ | ||
"name": "@antora/content-classifier", | ||
"version": "2.3.0-beta.1", | ||
"version": "2.3.0-beta.2", | ||
"description": "Organizes aggregated content into a virtual file catalog for use in an Antora documentation pipeline.", | ||
@@ -19,7 +19,7 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/asciidoc-loader": "2.3.0-beta.1", | ||
"@antora/asciidoc-loader": "2.3.0-beta.2", | ||
"vinyl": "~2.2" | ||
}, | ||
"devDependencies": { | ||
"@antora/content-aggregator": "2.3.0-beta.1" | ||
"@antora/content-aggregator": "2.3.0-beta.2" | ||
}, | ||
@@ -26,0 +26,0 @@ "engines": { |
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
30108
712
+ Added@antora/asciidoc-loader@2.3.0-beta.2(transitive)
- Removed@antora/asciidoc-loader@2.3.0-beta.1(transitive)