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.2.0 to 2.3.0-alpha.1

45

lib/classify-content.js

@@ -18,13 +18,15 @@ 'use strict'

* @param {Object} aggregate - The raw aggregate of virtual file objects to be classified.
* @param {Object} [siteAsciiDocConfig=undefined] - Site-wide AsciiDoc processor configuration options.
* @returns {ContentCatalog} A structured catalog of content components and virtual content files.
*/
function classifyContent (playbook, aggregate) {
const contentCatalog = aggregate.reduce(
(accum, { name, version, display_version: displayVersion, prerelease, title, start_page: startAt, nav, files }) => {
files.forEach((file) => allocateSrc(file, name, version, nav) && accum.addFile(file))
accum.registerComponentVersion(name, version, { displayVersion, title, prerelease, startPage: startAt })
return accum
},
new ContentCatalog(playbook)
)
function classifyContent (playbook, aggregate, siteAsciiDocConfig = undefined) {
if (!siteAsciiDocConfig) siteAsciiDocConfig = require('@antora/asciidoc-loader').resolveConfig(playbook)
const contentCatalog = aggregate.reduce((catalog, descriptor) => {
const { name, version, nav, files } = descriptor
delete descriptor.files
files.forEach((file) => allocateSrc(file, name, version, nav) && catalog.addFile(file))
descriptor.asciidocConfig = resolveAsciiDocConfig(siteAsciiDocConfig, descriptor)
catalog.registerComponentVersion(name, version, descriptor)
return catalog
}, new ContentCatalog(playbook))
registerSiteStartPage(playbook, contentCatalog)

@@ -137,2 +139,27 @@ return contentCatalog

function resolveAsciiDocConfig (siteAsciiDocConfig, { asciidoc }) {
const scopedAttributes = (asciidoc || {}).attributes
if (scopedAttributes) {
const siteAttributes = siteAsciiDocConfig.attributes
if (siteAttributes) {
const attributes = Object.keys(scopedAttributes).reduce((accum, name) => {
if (name in siteAttributes) {
const currentVal = siteAttributes[name]
if (currentVal === false || String(currentVal).endsWith('@')) accum[name] = scopedAttributes[name]
} else {
accum[name] = scopedAttributes[name]
}
return accum
}, {})
return Object.keys(attributes).length
? Object.assign({}, siteAsciiDocConfig, { attributes: Object.assign({}, siteAttributes, attributes) })
: siteAsciiDocConfig
} else {
return Object.assign({}, siteAsciiDocConfig, { attributes: scopedAttributes })
}
} else {
return siteAsciiDocConfig
}
}
function calculateRootPath (depth) {

@@ -139,0 +166,0 @@ return depth

14

lib/content-catalog.js

@@ -25,5 +25,5 @@ 'use strict'

registerComponentVersion (name, version, { displayVersion, prerelease, title, startPage } = {}) {
const startPageSpec = startPage
startPage = this.resolvePage(startPageSpec || 'index.adoc', { component: name, version, module: 'ROOT' })
registerComponentVersion (name, version, descriptor = {}) {
const { asciidocConfig, displayVersion, prerelease, title, startPage: startPageSpec } = descriptor
let startPage = this.resolvePage(startPageSpec || 'index.adoc', { component: name, version, module: 'ROOT' })
if (!startPage) {

@@ -40,6 +40,6 @@ //if (startPageSpec) throw new Error(`Start page specified for ${version}@${name} not found: ` + startPageSpec)

const componentVersion = {
version,
displayVersion: displayVersion || version,
title: title || name,
url: startPage.pub.url,
version,
}

@@ -49,6 +49,8 @@ if (prerelease) {

if (!displayVersion && (typeof prerelease === 'string' || prerelease instanceof String)) {
const sep = prerelease.startsWith('-') || prerelease.startsWith('.') ? '' : ' '
const ch0 = prerelease.charAt()
const sep = ch0 === '-' || ch0 === '.' ? '' : ' '
componentVersion.displayVersion = `${version}${sep}${prerelease}`
}
}
if (asciidocConfig) componentVersion.asciidocConfig = asciidocConfig
const component = this[$components][name]

@@ -95,3 +97,3 @@ if (component) {

const id = this[$generateId](file.src)
if (this[$files][id]) {
if (id in this[$files]) {
throw new Error(`Duplicate ${file.src.family}: ${id.replace(':' + file.src.family + '$', ':')}`)

@@ -98,0 +100,0 @@ }

'use strict'
const NUMBERS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
const { isInteger } = Number

@@ -26,5 +27,5 @@ /**

if (semverA) {
return semverB ? -1 * semverCompare(semverA, semverB) : 1
return semverB ? -semverCompare(semverA, semverB) : 1
} else {
return semverB ? -1 : -1 * a.localeCompare(b, 'en', { numeric: true })
return semverB ? -1 : -a.localeCompare(b, 'en', { numeric: true })
}

@@ -34,8 +35,8 @@ }

function resolveSemver (str) {
const char0 = str.charAt()
if (char0 === 'v') {
if (NUMBERS.includes(str.charAt(1)) && (str = str.substr(1)) && (~str.indexOf('.') || isNumber(str.charAt()))) {
const chr0 = str.charAt()
if (chr0 === 'v') {
if (isDigit(str.charAt(1)) && (str = str.substr(1)) && (~str.indexOf('.') || isDigit(str.charAt()))) {
return str
}
} else if (NUMBERS.includes(char0) && (~str.indexOf('.') || isNumber(str))) {
} else if (isDigit(chr0) && (~str.indexOf('.') || isInteger(Number(str)))) {
return str

@@ -45,4 +46,4 @@ }

function isNumber (str) {
return !isNaN(Number(str))
function isDigit (chr) {
return NUMBERS.includes(chr)
}

@@ -49,0 +50,0 @@

{
"name": "@antora/content-classifier",
"version": "2.2.0",
"version": "2.3.0-alpha.1",
"description": "Organizes aggregated content into a virtual file catalog for use in an Antora documentation pipeline.",

@@ -23,3 +23,3 @@ "license": "MPL-2.0",

"devDependencies": {
"@antora/content-aggregator": "2.2.0"
"@antora/content-aggregator": "2.3.0-alpha.1"
},

@@ -26,0 +26,0 @@ "engines": {

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