From e2f3ba2245dafc3dcd4f3e6609023af3b7c2addc Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 24 Oct 2022 18:07:29 -0600 Subject: [PATCH] add release line extension --- antora-playbook.yml | 2 +- build.gradle | 3 +- lib/antora/extensions/major-minor-segment.js | 204 ------------------- 3 files changed, 3 insertions(+), 206 deletions(-) delete mode 100644 lib/antora/extensions/major-minor-segment.js diff --git a/antora-playbook.yml b/antora-playbook.yml index 2bfe895764..85336f7f32 100644 --- a/antora-playbook.yml +++ b/antora-playbook.yml @@ -3,7 +3,7 @@ antora: - ./lib/antora/extensions/inject-collector-config.js - '@antora/collector-extension' - ./lib/antora/extensions/version-fix.js - - ./lib/antora/extensions/major-minor-segment.js + - '@opendevise/antora-release-line-extension' site: title: Spring Security url: https://docs.spring.io/spring-security/reference diff --git a/build.gradle b/build.gradle index ea56af613a..962af95b60 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ antora { 'ALGOLIA_INDEX_NAME': 'security-docs' ] dependencies = [ - '@antora/collector-extension': '1.0.0-alpha.2' + '@antora/collector-extension': '1.0.0-alpha.2', + '@opendevise/antora-release-line-extension': '1.0.0-alpha.1' ] } diff --git a/lib/antora/extensions/major-minor-segment.js b/lib/antora/extensions/major-minor-segment.js deleted file mode 100644 index 6cf7152b2c..0000000000 --- a/lib/antora/extensions/major-minor-segment.js +++ /dev/null @@ -1,204 +0,0 @@ -// https://gitlab.com/antora/antora/-/issues/132#note_712132072 -'use strict' - -const { posix: path } = require('path') - -module.exports.register = function({ config }) { - this.on('contentClassified', ({ contentCatalog }) => { - contentCatalog.getComponents().forEach(component => { - const componentName = component.name; - const generationToVersion = new Map(); - component.versions.forEach(version => { - const generation = getGeneration(version.version); - const original = generationToVersion.get(generation); - if (original === undefined || (original.prerelease && !version.prerelease)) { - generationToVersion.set(generation, version); - } - }); - - const versionToGeneration = Array.from(generationToVersion.entries()).reduce((acc, entry) => { - const [ generation, version ] = entry; - acc.set(version.version, generation); - return acc; - }, new Map()); - - contentCatalog.findBy({ component: componentName }).forEach((file) => { - const candidateVersion = file.src.version; - if (versionToGeneration.has(candidateVersion)) { - const generation = versionToGeneration.get(candidateVersion); - if (file.out) { - if (file.out) { - file.out.dirname = file.out.dirname.replace(candidateVersion, generation) - file.out.path = file.out.path.replace(candidateVersion, generation); - } - } - if (file.pub) { - file.pub.url = file.pub.url.replace(candidateVersion, generation) - } - } - }); - versionToGeneration.forEach((generation, mappedVersion) => { - contentCatalog.getComponent(componentName).versions.filter(version => version.version === mappedVersion).forEach((version) => { - version.url = version.url.replace(mappedVersion, generation); - }) - const symbolicVersionAlias = createSymbolicVersionAlias( - componentName, - mappedVersion, - generation, - 'redirect:to' - ) - symbolicVersionAlias.src.version = generation; - contentCatalog.addFile(symbolicVersionAlias); - }); - }) - }) -} - -function createSymbolicVersionAlias (component, version, symbolicVersionSegment, strategy) { - if (symbolicVersionSegment == null || symbolicVersionSegment === version) return - const family = 'alias' - const baseVersionAliasSrc = { component, module: 'ROOT', family, relative: '', basename: '', stem: '', extname: '' } - const symbolicVersionAliasSrc = Object.assign({}, baseVersionAliasSrc, { version: symbolicVersionSegment }) - const symbolicVersionAlias = { - src: symbolicVersionAliasSrc, - pub: computePub( - symbolicVersionAliasSrc, - computeOut(symbolicVersionAliasSrc, family, symbolicVersionSegment), - family - ), - } - const originalVersionAliasSrc = Object.assign({}, baseVersionAliasSrc, { version }) - const originalVersionSegment = computeVersionSegment(component, version, 'original') - const originalVersionAlias = { - src: originalVersionAliasSrc, - pub: computePub( - originalVersionAliasSrc, - computeOut(originalVersionAliasSrc, family, originalVersionSegment), - family - ), - } - if (strategy === 'redirect:to') { - originalVersionAlias.out = undefined - originalVersionAlias.rel = symbolicVersionAlias - return originalVersionAlias - } else { - symbolicVersionAlias.out = undefined - symbolicVersionAlias.rel = originalVersionAlias - return symbolicVersionAlias - } -} - - -function computeOut (src, family, version, htmlUrlExtensionStyle) { - let { component, module: module_, basename, extname, relative, stem } = src - if (component === 'ROOT') component = '' - if (module_ === 'ROOT') module_ = '' - let indexifyPathSegment = '' - let familyPathSegment = '' - - if (family === 'page') { - if (stem !== 'index' && htmlUrlExtensionStyle === 'indexify') { - basename = 'index.html' - indexifyPathSegment = stem - } else if (extname === '.adoc') { - basename = stem + '.html' - } - } else if (family === 'image') { - familyPathSegment = '_images' - } else if (family === 'attachment') { - familyPathSegment = '_attachments' - } - const modulePath = path.join(component, version, module_) - const dirname = path.join(modulePath, familyPathSegment, path.dirname(relative), indexifyPathSegment) - const path_ = path.join(dirname, basename) - const moduleRootPath = path.relative(dirname, modulePath) || '.' - const rootPath = path.relative(dirname, '') || '.' - - return { dirname, basename, path: path_, moduleRootPath, rootPath } -} - -function computePub (src, out, family, version, htmlUrlExtensionStyle) { - const pub = {} - let url - if (family === 'nav') { - const component = src.component || 'ROOT' - const urlSegments = component === 'ROOT' ? [] : [component] - if (version) urlSegments.push(version) - const module_ = src.module || 'ROOT' - if (module_ !== 'ROOT') urlSegments.push(module_) - // an artificial URL used for resolving page references in navigation model - url = '/' + urlSegments.join('/') + '/' - pub.moduleRootPath = '.' - } else if (family === 'page') { - const urlSegments = out.path.split('/') - const lastUrlSegmentIdx = urlSegments.length - 1 - if (htmlUrlExtensionStyle === 'drop') { - // drop just the .html extension or, if the filename is index.html, the whole segment - const lastUrlSegment = urlSegments[lastUrlSegmentIdx] - urlSegments[lastUrlSegmentIdx] = - lastUrlSegment === 'index.html' ? '' : lastUrlSegment.substr(0, lastUrlSegment.length - 5) - } else if (htmlUrlExtensionStyle === 'indexify') { - urlSegments[lastUrlSegmentIdx] = '' - } - url = '/' + urlSegments.join('/') - } else { - url = '/' + out.path - if (family === 'alias' && !src.relative.length) pub.splat = true - } - - pub.url = ~url.indexOf(' ') ? url.replace(SPACE_RX, '%20') : url - - if (out) { - pub.moduleRootPath = out.moduleRootPath - pub.rootPath = out.rootPath - } - - return pub -} - -function computeVersionSegment (name, version, mode) { - if (mode === 'original') return !version || version === 'master' ? '' : version - const strategy = this.latestVersionUrlSegmentStrategy - // NOTE: special exception; revisit in Antora 3 - if (!version || version === 'master') { - if (mode !== 'alias') return '' - if (strategy === 'redirect:to') return - } - if (strategy === 'redirect:to' || strategy === (mode === 'alias' ? 'redirect:from' : 'replace')) { - const component = this.getComponent(name) - const componentVersion = component && this.getComponentVersion(component, version) - if (componentVersion) { - const segment = - componentVersion === component.latest - ? this.latestVersionUrlSegment - : componentVersion === component.latestPrerelease - ? this.latestPrereleaseVersionUrlSegment - : undefined - return segment == null ? version : segment - } - } - return version -} - -function getGeneration(version) { - if (!version) return version; - const firstIndex = version.indexOf('.') - if (firstIndex < 0) { - return version; - } - const secondIndex = version.indexOf('.', firstIndex + 1); - const result = version.substr(0, secondIndex); - return result; -} - -function out(args) { - console.log(JSON.stringify(args, no_data, 2)); -} - - -function no_data(key, value) { - if (key == "data" || key == "files") { - return value ? "__data__" : value; - } - return value; -}