@redpanda-data/docs-extensions-and-macros
Advanced tools
Comparing version 3.5.4 to 3.5.5
@@ -17,3 +17,3 @@ 'use strict'; | ||
if (latestTag) { | ||
source.tags[0] = latestTag; | ||
source.tags[0] = `v${latestTag}`; | ||
this.updateVariables({ playbook }); | ||
@@ -20,0 +20,0 @@ } |
@@ -14,3 +14,3 @@ 'use strict'; | ||
if ('findBy' in aliases) aliases = aliases.findBy({ family: 'alias' }) // @deprecated remove in Antora 4 | ||
if (!aliases.length) return [] | ||
if (!(aliases = aliases.filter((it) => it.pub.url !== it.rel.pub.url)).length) return [] | ||
let siteUrl = playbook.site.url | ||
@@ -36,3 +36,2 @@ if (siteUrl) siteUrl = stripTrailingSlash(siteUrl, '') | ||
} | ||
return produceRedirectsDelegate.call(this, playbook, aliases) | ||
} | ||
@@ -77,3 +76,2 @@ }) | ||
const rules = files.reduce((accum, file) => { | ||
if (isRedirectLoop(file)) return accum | ||
delete file.out | ||
@@ -103,3 +101,2 @@ let fromUrl = file.pub.url | ||
const rules = files.reduce((accum, file) => { | ||
if (isRedirectLoop(file)) return accum | ||
delete file.out | ||
@@ -124,3 +121,2 @@ const fromUrl = urlPath + file.pub.url | ||
const rules = files.map((file) => { | ||
if (isRedirectLoop(file)) return '' | ||
delete file.out | ||
@@ -143,3 +139,2 @@ let fromUrl = file.pub.url | ||
for (const file of files) { | ||
if (isRedirectLoop(file)) continue | ||
const content = createStaticRedirectContents(file, siteUrl) + '\n'; | ||
@@ -175,6 +170,1 @@ file.contents = Buffer.from(content); | ||
function isRedirectLoop (file) { | ||
if (file.pub.url === file.rel.pub.url) return true | ||
return false | ||
} | ||
@@ -1,40 +0,33 @@ | ||
module.exports.register = function ({ config }) { | ||
const { family = 'attachment' } = config; | ||
const logger = this.getLogger('replace-attributes-in-attachments-extension'); | ||
'use strict'; | ||
const sanitizeAttributeValue = (value) => String(value).replace("@", ""); | ||
module.exports.register = function () { | ||
this.on('contentClassified', ({ contentCatalog }) => { | ||
const componentVersionTable = contentCatalog.getComponents().reduce((componentMap, component) => { | ||
componentMap[component.name] = component.versions.reduce((versionMap, componentVersion) => { | ||
versionMap[componentVersion.version] = componentVersion; | ||
return versionMap; | ||
}, {}); | ||
return componentMap; | ||
}, {}); | ||
this.on('contentClassified', ({contentCatalog}) => { | ||
for (const { versions } of contentCatalog.getComponents()) { | ||
for (const { name: component, version, asciidoc } of versions) { | ||
const attachments = contentCatalog.findBy({ component, version, family }); | ||
if (component == 'api') continue; | ||
for (const attachment of attachments) { | ||
let contentString = attachment['_contents'].toString('utf8'); | ||
if (!asciidoc.attributes) continue; | ||
// Replace general attributes | ||
for (const key in asciidoc.attributes) { | ||
const placeholder = "{" + key + "}"; | ||
const sanitizedValue = sanitizeAttributeValue(asciidoc.attributes[key]); | ||
contentString = contentString.replace(new RegExp(placeholder, 'g'), sanitizedValue); | ||
} | ||
// Specific replacements for YAML files | ||
if (attachment.out.path.endsWith('.yaml') || attachment.out.path.endsWith('.yml')) { | ||
const redpandaVersionRegex = /(\$\{REDPANDA_VERSION[^\}]*\})/g; | ||
const redpandaConsoleVersionRegex = /(\$\{REDPANDA_CONSOLE_VERSION[^\}]*\})/g; | ||
const fullVersion = asciidoc.attributes['full-version'] ? sanitizeAttributeValue(asciidoc.attributes['full-version']) : ''; | ||
const latestConsoleVersion = asciidoc.attributes['latest-console-version'] ? sanitizeAttributeValue(asciidoc.attributes['latest-console-version']) : ''; | ||
contentString = contentString.replace(redpandaVersionRegex, fullVersion); | ||
contentString = contentString.replace(redpandaConsoleVersionRegex, latestConsoleVersion); | ||
} | ||
attachment['_contents'] = Buffer.from(contentString, "utf-8"); | ||
} | ||
} | ||
} | ||
contentCatalog.findBy({ family: 'attachment' }).forEach((attachment) => { | ||
const componentVersion = componentVersionTable[attachment.src.component][attachment.src.version]; | ||
let attributes = componentVersion.asciidoc?.attributes; | ||
if (!attributes) return; | ||
attributes = Object.entries(attributes).reduce((accum, [name, val]) => { | ||
const stringValue = String(val); // Ensure val is a string | ||
accum[name] = stringValue.endsWith('@') ? stringValue.slice(0, stringValue.length - 1) : stringValue; | ||
return accum; | ||
}, {}); | ||
let modified; | ||
const result = attachment.contents.toString().replace(/\{([\p{Alpha}\d_][\p{Alpha}\d_-]*)\}/gu, (match, name) => { | ||
if (!(name in attributes)) return match; | ||
modified = true; | ||
let value = attributes[name]; | ||
if (value.endsWith('@')) value = value.slice(0, value.length - 1); | ||
return value; | ||
}); | ||
if (modified) attachment.contents = Buffer.from(result); | ||
}); | ||
}); | ||
} | ||
}; |
@@ -10,6 +10,4 @@ 'use strict'; | ||
versions.forEach(({ name: component, version, navigation: nav, url: defaultUrl }) => { | ||
if (component === 'api') return; | ||
if (component === 'api' || component === 'redpanda-labs') return; | ||
if (!nav) return; | ||
const currentComponent = contentCatalog.getComponent(component); | ||
const prerelease = currentComponent && currentComponent.latestPrerelease ? currentComponent.latestPrerelease : false; | ||
@@ -34,6 +32,3 @@ const navEntriesByUrl = getNavEntriesByUrl(nav); | ||
if (unlistedPages.length && component === 'redpanda-connect') { | ||
// Some component pages for Redpanda Connect are autogenerated. This function tries to add unlisted component pages to the nav in case a new one gets created without updating the nav. | ||
addRedpandaConnectPagesToNav(nav[0].items, unlistedPages); | ||
} else if (unlistedPages.length && addToNavigation) { | ||
if (unlistedPages.length && addToNavigation) { | ||
nav.push({ | ||
@@ -60,29 +55,2 @@ content: unlistedPagesHeading, | ||
function addRedpandaConnectPagesToNav(navItems, pages) { | ||
// get the Components nav section | ||
let componentsSection = navItems.find(item => item.content === 'Components'); | ||
if (!componentsSection) return; | ||
pages.forEach(page => { | ||
const dirname = page.out.dirname; | ||
if (!dirname.includes('/components/')) return; | ||
const heading = page.asciidoc.attributes.doctitle; | ||
const pathParts = dirname.split('/').slice(2); // Get the type | ||
// get existing nav items inside the Components tree | ||
let currentLevel = componentsSection.items; | ||
pathParts.forEach((part, index) => { | ||
const capitalizedPart = part.charAt(0).toUpperCase() + part.slice(1); | ||
let section = currentLevel.find(item => item.content === capitalizedPart); | ||
if (!section) { | ||
section = { content: capitalizedPart, items: [], root: index === 0 }; | ||
currentLevel.push(section); | ||
} | ||
currentLevel = section.items; | ||
}); | ||
currentLevel.push({ content: page.asciidoc.navtitle || page.src.stem, url: page.pub.url, urlType: 'internal' }); | ||
}); | ||
} | ||
function removePageFromNav(navItems, urlToRemove) { | ||
@@ -89,0 +57,0 @@ // Remove the page from the navigation items |
@@ -17,5 +17,2 @@ 'use strict'; | ||
// Check if the page is part of the beta version | ||
const isPrerelease = component && pageVersion && component.latestPrerelease && component.latestPrerelease.version === pageVersion; | ||
// Check the conditions for unpublishing the page | ||
@@ -25,3 +22,3 @@ const shouldUnpublish = ( | ||
(page.asciidoc?.attributes['publish-only-during-beta'] | ||
&& !isPrerelease // No beta version available, meaning the beta period has ended | ||
&& !page.asciidoc?.attributes['page-component-version-is-prerelease'] // Not part of a beta version, meaning the beta period has ended | ||
) | ||
@@ -28,0 +25,0 @@ ); |
@@ -33,3 +33,9 @@ const GetLatestRedpandaVersion = require('./get-latest-redpanda-version') | ||
components.forEach(component => { | ||
let prerelease = component.latestPrerelease; | ||
component.versions.forEach(({ name, version, asciidoc }) => { | ||
// This attribute is used for conditionally rendering content for beta releases. | ||
// It is also used in the `unpublish-pages` extension to unpublish beta pages that aren't part of a beta version. | ||
if (prerelease && prerelease.version === version) { | ||
asciidoc.attributes['page-component-version-is-prerelease'] = 'true' | ||
} | ||
if (LatestConsoleVersion) { | ||
@@ -36,0 +42,0 @@ asciidoc.attributes['latest-console-version'] = `${LatestConsoleVersion}@` |
{ | ||
"name": "@redpanda-data/docs-extensions-and-macros", | ||
"version": "3.5.4", | ||
"version": "3.5.5", | ||
"description": "Antora extensions and macros developed for Redpanda documentation.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
107190
1875