Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antora/content-classifier

Package Overview
Dependencies
Maintainers
2
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/content-classifier - npm Package Compare versions

Comparing version 2.3.3 to 2.3.4

111

lib/content-catalog.js

@@ -28,12 +28,19 @@ 'use strict'

let startPage
let startPageSrc
const indexPageId = { component: name, version, module: 'ROOT', family: 'page', relative: 'index.adoc' }
if (startPageSpec) {
const { src: startPageSrc } = (startPage = this.resolvePage(startPageSpec, indexPageId)) || {}
if (startPageSrc && startPageSrc.component === name && startPageSrc.version === version) {
if (!(startPageSrc.module === 'ROOT' && startPageSrc.relative === 'index.adoc')) {
if (
(startPage = this.resolvePage(startPageSpec, indexPageId)) &&
(startPageSrc = startPage.src).component === name &&
startPageSrc.version === version
) {
if ((startPageSrc.module !== 'ROOT' || startPageSrc.relative !== 'index.adoc') && !this.getById(indexPageId)) {
this.addFile({ mediaType: 'text/html', src: inflateSrc(indexPageId, 'alias'), rel: startPage })
}
} else {
console.warn(
`Start page specified for ${version}@${name} ${startPage === false ? 'has invalid syntax' : 'not found'}: ` +
startPageSpec
)
startPage = this.getById(indexPageId)
console.warn(`Start page specified for ${version}@${name} not found: ${startPageSpec}`)
}

@@ -47,5 +54,4 @@ } else {

// QUESTION: should we warn if the default start page cannot be found?
const startPageSrc = inflateSrc(indexPageId)
componentVersion.url = computePub(
startPageSrc,
(startPageSrc = inflateSrc(indexPageId)),
computeOut(startPageSrc, startPageSrc.family, this.htmlUrlExtensionStyle),

@@ -113,9 +119,19 @@ startPageSrc.family,

addFile (file) {
const key = generateKey(file.src)
const src = file.src
const key = generateKey(src)
if (this[$files].has(key)) {
throw new Error(`Duplicate ${file.src.family}: ${key.replace(':' + file.src.family + '$', ':')}`)
const family = src.family
if (family === 'alias') {
throw new Error(`Duplicate alias: ${generateResourceSpec(src)}`)
} else {
const details = [this.getById(src), file].map((it, idx) => ` ${idx + 1}: ${getFileLocation(it)}`).join('\n')
if (family === 'nav') {
throw new Error(`Duplicate nav in ${src.version}@${src.component}: ${file.path}\n${details}`)
} else {
throw new Error(`Duplicate ${family}: ${generateResourceSpec(src)}\n${details}`)
}
}
}
if (!File.isVinyl(file)) file = new File(file)
const family = file.src.family
const actingFamily = family === 'alias' ? file.rel.src.family : family
const actingFamily = src.family === 'alias' ? file.rel.src.family : src.family
let publishable

@@ -128,9 +144,9 @@ if (file.out) {

(actingFamily === 'page' || actingFamily === 'image' || actingFamily === 'attachment') &&
!~('/' + file.src.relative).indexOf('/_')
!~('/' + src.relative).indexOf('/_')
) {
publishable = true
file.out = computeOut(file.src, actingFamily, this.htmlUrlExtensionStyle)
file.out = computeOut(src, actingFamily, this.htmlUrlExtensionStyle)
}
if (!file.pub && (publishable || actingFamily === 'nav')) {
file.pub = computePub(file.src, file.out, actingFamily, this.htmlUrlExtensionStyle)
file.pub = computePub(src, file.out, actingFamily, this.htmlUrlExtensionStyle)
}

@@ -169,3 +185,3 @@ this[$files].set(key, file)

return (component.versions || (this.getComponent(component) || {}).versions || []).find(
(candidate) => candidate.version === version
({ version: candidate }) => candidate === version
)

@@ -232,4 +248,8 @@ }

return this.addFile({ mediaType: 'text/html', src: inflateSrc(Object.assign({}, START_ALIAS_ID), 'alias'), rel })
} else if (rel === false) {
console.warn(`Start page specified for site has invalid syntax: ${startPageSpec}`)
} else if (~startPageSpec.indexOf(':')) {
console.warn(`Start page specified for site not found: ${startPageSpec}`)
} else {
console.warn(`Start page specified for site not found: ${startPageSpec}`)
console.warn(`Missing component name in start page for site: ${startPageSpec}`)
}

@@ -239,4 +259,4 @@ }

// QUESTION should this be addPageAlias?
registerPageAlias (spec, rel) {
const src = parseResourceId(spec, rel.src, 'page', ['page'])
registerPageAlias (spec, target) {
const src = parseResourceId(spec, target.src, 'page', ['page'])
// QUESTION should we throw an error if alias is invalid?

@@ -250,8 +270,18 @@ if (!src) return

if (existingPage) {
// TODO we'll need some way to easily get a displayable page ID
let qualifiedSpec = generateKey(existingPage.src)
qualifiedSpec = qualifiedSpec.replace(':page$', ':')
const message = `Page alias cannot reference ${existingPage === rel ? 'itself' : 'an existing page'}`
throw new Error(message + ': ' + qualifiedSpec)
throw new Error(
existingPage === target
? `Page cannot define alias that references itself: ${generateResourceSpec(src)}` +
` (specified as: ${spec})\n source: ${getFileLocation(existingPage)}`
: `Page alias cannot reference an existing page: ${generateResourceSpec(src)} (specified as: ${spec})\n` +
` source: ${getFileLocation(target)}\n` +
` existing page: ${getFileLocation(existingPage)}`
)
}
const existingAlias = this.getById(Object.assign({}, src, { family: 'alias' }))
if (existingAlias) {
throw new Error(
`Duplicate alias: ${generateResourceSpec(src)} (specified as: ${spec})\n` +
` source: ${getFileLocation(target)}`
)
}
} else if (!src.version) {

@@ -262,6 +292,6 @@ // QUESTION should we skip registering alias in this case?

// QUESTION should we use src.origin instead of rel with type='link'?
//src.origin = { type: 'link', target: rel }
//src.origin = { type: 'link', target }
// NOTE the redirect producer will populate contents when the redirect facility is 'static'
//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 })
return this.addFile({ mediaType: 'text/html', src: inflateSrc(src, 'alias'), rel: target })
}

@@ -322,2 +352,11 @@

function generateResourceSpec ({ component, version, module: module_, family, relative }, shorthand = true) {
//if (module_ == null && family === 'nav') return `${version}@${component}:nav$${relative}`
return (
`${version}@${component}:${shorthand && module_ === 'ROOT' ? '' : module_}:` +
(family === 'page' || family === 'alias' ? '' : `${family}$`) +
relative
)
}
function inflateSrc (src, family = 'page', mediaType = 'text/asciidoc') {

@@ -345,12 +384,13 @@ const 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 = ''
if (family === 'page' && stem !== 'index' && htmlUrlExtensionStyle === 'indexify') {
basename = 'index.html'
indexifyPathSegment = stem
}
let familyPathSegment = ''
let familyPathSegment = ''
if (family === 'image') {
if (family === 'page') {
if (stem !== 'index' && htmlUrlExtensionStyle === 'indexify') {
basename = 'index.html'
indexifyPathSegment = stem
} else if (src.mediaType === 'text/asciidoc') {
basename = stem + '.html'
}
} else if (family === 'image') {
familyPathSegment = '_images'

@@ -406,2 +446,9 @@ } else if (family === 'attachment') {

function getFileLocation ({ path: path_, src: { abspath, origin } }) {
return (
abspath ||
(origin ? `${path.join(origin.startPath, path_)} in ${origin.url} (ref: ${origin.branch || origin.tag})` : path_)
)
}
module.exports = ContentCatalog

@@ -9,7 +9,7 @@ 'use strict'

* Parses the specified contextual resource ID spec into a resource ID object using parseResourceId,
* then attempts to locate a file with this resource the catalog. If a component is specified, but
* then attempts to locate a file with this resource ID in the catalog. If a component is specified, but
* not a version, the latest version of the component is used from the catalog. If a file cannot be
* resolved, and the family is "page", then the search is attempted again for an 'alias'. If a file
* resolved, and the family is "page", then the search is attempted again for an "alias". If a file
* still cannot be found, the function returns undefined. If the spec does not match the resource ID
* syntax, this function throws an error.
* syntax, or the specified family is not permitted, this function returns false.
*

@@ -25,4 +25,4 @@ * @memberof content-classifier

*
* @return {File} The virtual file to which the contextual resource ID spec refers, or undefined if
* the file cannot be resolved.
* @return {File} The virtual file to which the contextual resource ID spec refers, undefined if
* the file cannot be resolved, or false if the resource ID spec is invalid.
*/

@@ -32,4 +32,3 @@ function resolveResource (spec, catalog, ctx = {}, defaultFamily = undefined, permittedFamilies = undefined) {

if (!id) throw new Error(`Invalid ${defaultFamily || 'resource'} ID syntax`)
if (!id.family) return
if (!id || !id.family) return false
if (!id.version) {

@@ -36,0 +35,0 @@ const component = catalog.getComponent(id.component)

{
"name": "@antora/content-classifier",
"version": "2.3.3",
"version": "2.3.4",
"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.3",
"@antora/asciidoc-loader": "2.3.4",
"vinyl": "~2.2"
},
"devDependencies": {
"@antora/content-aggregator": "2.3.3"
"@antora/content-aggregator": "2.3.4"
},

@@ -40,3 +40,3 @@ "engines": {

],
"gitHead": "0e0b6673b62cd6e89d11124f849e74f574d53317"
"gitHead": "5a40191c970ece6baecbd1a3a7a599d7161351a9"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc