@redpanda-data/docs-extensions-and-macros 3.5.4 → 3.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.adoc +15 -5
- package/extensions/modify-connect-tag-playbook.js +1 -1
- package/extensions/produce-redirects.js +1 -11
- package/extensions/replace-attributes-in-attachments.js +43 -32
- package/extensions/unlisted-pages.js +2 -34
- package/extensions/unpublish-pages.js +1 -4
- package/extensions/version-fetcher/set-latest-version.js +6 -0
- package/package.json +1 -1
package/README.adoc
CHANGED
|
@@ -38,17 +38,17 @@ When you have Node.js installed, use the following command to install the `antor
|
|
|
38
38
|
npm i @redpanda-data/docs-extensions-and-macros
|
|
39
39
|
----
|
|
40
40
|
|
|
41
|
-
To use the development version
|
|
41
|
+
To use the development version, refer to the <<development-quickstart,Development Quickstart>>.
|
|
42
42
|
|
|
43
43
|
== Antora Extensions
|
|
44
44
|
|
|
45
|
-
This section documents the Antora extensions
|
|
45
|
+
This section documents the Antora extensions provided by this library and how to configure them.
|
|
46
46
|
|
|
47
47
|
IMPORTANT: Ensure you register each extension under the `antora.extensions` key in the playbook, not the `asciidoc.extensions` key.
|
|
48
48
|
|
|
49
49
|
=== Algolia indexer
|
|
50
50
|
|
|
51
|
-
This extension generates an Algolia index for each version of each component. The index entries are then saved to Algolia using the `saveObjects()` method, and also saved as JSON files in the site catalog. JSON files are published to the site root using the
|
|
51
|
+
This extension generates an Algolia index for each version of each component. The index entries are then saved to Algolia using the `saveObjects()` method, and also saved as JSON files in the site catalog. JSON files are published to the site root using the template `algolia-<component>-<version>.json`.
|
|
52
52
|
|
|
53
53
|
NOTE: Only pages that include an `<article>` element with the `doc` class are indexed.
|
|
54
54
|
|
|
@@ -127,9 +127,19 @@ antora:
|
|
|
127
127
|
|
|
128
128
|
This extension fetches the latest release versions from GitHub.
|
|
129
129
|
|
|
130
|
-
The
|
|
130
|
+
The following attributes are available to all versions of all Antora components:
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
`latest-console-version`: The latest release version of Redpanda Console.
|
|
133
|
+
`latest-connect-version`: The latest release version of Redpanda Connect.
|
|
134
|
+
`redpanda-beta-version`: The latest RC version of Redpanda.
|
|
135
|
+
`redpanda-beta-commit`: The commit hash for the latest RC version of Redpanda.
|
|
136
|
+
|
|
137
|
+
The following attributes are available to the latest version of the `ROOT` component (Redpanda docs):
|
|
138
|
+
|
|
139
|
+
`full-version`: The latest release version of Redpanda.
|
|
140
|
+
`latest-release-commit`: The commit hash for the latest release version of Redpanda.
|
|
141
|
+
`latest-operator-version`: The latest release version of the Redpanda Operator.
|
|
142
|
+
`latest-redpanda-helm-chart-version`: The latest release version of the Redpanda Helm chart.
|
|
133
143
|
|
|
134
144
|
==== Environment variables
|
|
135
145
|
|
|
@@ -11,7 +11,7 @@ module.exports.register = function () {
|
|
|
11
11
|
this.replaceFunctions({
|
|
12
12
|
produceRedirects (playbook, aliases) {
|
|
13
13
|
if ('findBy' in aliases) aliases = aliases.findBy({ family: 'alias' }) // @deprecated remove in Antora 4
|
|
14
|
-
if (!aliases.length) return []
|
|
14
|
+
if (!(aliases = aliases.filter((it) => it.pub.url !== it.rel.pub.url)).length) return []
|
|
15
15
|
let siteUrl = playbook.site.url
|
|
16
16
|
if (siteUrl) siteUrl = stripTrailingSlash(siteUrl, '')
|
|
17
17
|
const directoryRedirects = (playbook.urls.htmlExtensionStyle || 'default') !== 'default'
|
|
@@ -32,7 +32,6 @@ module.exports.register = function () {
|
|
|
32
32
|
default:
|
|
33
33
|
return unpublish(aliases)
|
|
34
34
|
}
|
|
35
|
-
return produceRedirectsDelegate.call(this, playbook, aliases)
|
|
36
35
|
}
|
|
37
36
|
})
|
|
38
37
|
})
|
|
@@ -72,7 +71,6 @@ function extractUrlPath (url) {
|
|
|
72
71
|
|
|
73
72
|
function createHttpdHtaccess (files, urlPath, directoryRedirects = false) {
|
|
74
73
|
const rules = files.reduce((accum, file) => {
|
|
75
|
-
if (isRedirectLoop(file)) return accum
|
|
76
74
|
delete file.out
|
|
77
75
|
let fromUrl = file.pub.url
|
|
78
76
|
fromUrl = ~fromUrl.indexOf('%20') ? `'${urlPath}${fromUrl.replace(ENCODED_SPACE_RX, ' ')}'` : urlPath + fromUrl
|
|
@@ -97,7 +95,6 @@ function createHttpdHtaccess (files, urlPath, directoryRedirects = false) {
|
|
|
97
95
|
// however, we keep it when generating the rules for clarity
|
|
98
96
|
function createNetlifyRedirects (files, urlPath, addDirectoryRedirects = false, useForceFlag = true) {
|
|
99
97
|
const rules = files.reduce((accum, file) => {
|
|
100
|
-
if (isRedirectLoop(file)) return accum
|
|
101
98
|
delete file.out
|
|
102
99
|
const fromUrl = urlPath + file.pub.url
|
|
103
100
|
const toUrl = urlPath + file.rel.pub.url
|
|
@@ -117,7 +114,6 @@ function createNetlifyRedirects (files, urlPath, addDirectoryRedirects = false,
|
|
|
117
114
|
|
|
118
115
|
function createNginxRewriteConf (files, urlPath) {
|
|
119
116
|
const rules = files.map((file) => {
|
|
120
|
-
if (isRedirectLoop(file)) return ''
|
|
121
117
|
delete file.out
|
|
122
118
|
let fromUrl = file.pub.url
|
|
123
119
|
fromUrl = ~fromUrl.indexOf('%20') ? `'${urlPath}${fromUrl.replace(ENCODED_SPACE_RX, ' ')}'` : urlPath + fromUrl
|
|
@@ -135,7 +131,6 @@ function createNginxRewriteConf (files, urlPath) {
|
|
|
135
131
|
|
|
136
132
|
function populateStaticRedirectFiles(files, siteUrl) {
|
|
137
133
|
for (const file of files) {
|
|
138
|
-
if (isRedirectLoop(file)) continue
|
|
139
134
|
const content = createStaticRedirectContents(file, siteUrl) + '\n';
|
|
140
135
|
file.contents = Buffer.from(content);
|
|
141
136
|
}
|
|
@@ -166,8 +161,3 @@ function regexpEscape (str) {
|
|
|
166
161
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // don't escape "-" since it's meaningless in a literal
|
|
167
162
|
}
|
|
168
163
|
|
|
169
|
-
function isRedirectLoop (file) {
|
|
170
|
-
if (file.pub.url === file.rel.pub.url) return true
|
|
171
|
-
return false
|
|
172
|
-
}
|
|
173
|
-
|
|
@@ -1,40 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
const { family = 'attachment' } = config;
|
|
3
|
-
const logger = this.getLogger('replace-attributes-in-attachments-extension');
|
|
1
|
+
'use strict';
|
|
4
2
|
|
|
3
|
+
module.exports.register = function () {
|
|
5
4
|
const sanitizeAttributeValue = (value) => String(value).replace("@", "");
|
|
5
|
+
this.on('contentClassified', ({ contentCatalog }) => {
|
|
6
|
+
const componentVersionTable = contentCatalog.getComponents().reduce((componentMap, component) => {
|
|
7
|
+
componentMap[component.name] = component.versions.reduce((versionMap, componentVersion) => {
|
|
8
|
+
versionMap[componentVersion.version] = componentVersion;
|
|
9
|
+
return versionMap;
|
|
10
|
+
}, {});
|
|
11
|
+
return componentMap;
|
|
12
|
+
}, {});
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
contentCatalog.findBy({ family: 'attachment' }).forEach((attachment) => {
|
|
15
|
+
const componentVersion = componentVersionTable[attachment.src.component][attachment.src.version];
|
|
16
|
+
let attributes = componentVersion.asciidoc?.attributes;
|
|
17
|
+
if (!attributes) return;
|
|
18
|
+
attributes = Object.entries(attributes).reduce((accum, [name, val]) => {
|
|
19
|
+
const stringValue = String(val); // Ensure val is a string
|
|
20
|
+
accum[name] = stringValue.endsWith('@') ? stringValue.slice(0, stringValue.length - 1) : stringValue;
|
|
21
|
+
return accum;
|
|
22
|
+
}, {});
|
|
23
|
+
let modified;
|
|
24
|
+
let contentString = attachment.contents.toString();
|
|
25
|
+
// Specific replacements for YAML files
|
|
26
|
+
if (attachment.out.path.endsWith('.yaml') || attachment.out.path.endsWith('.yml')) {
|
|
27
|
+
const redpandaVersionRegex = /(\$\{REDPANDA_VERSION[^\}]*\})/g;
|
|
28
|
+
const redpandaConsoleVersionRegex = /(\$\{REDPANDA_CONSOLE_VERSION[^\}]*\})/g;
|
|
29
|
+
let fullVersion = attributes['full-version'] ? sanitizeAttributeValue(attributes['full-version']) : '';
|
|
30
|
+
const latestConsoleVersion = attributes['latest-console-version'] ? sanitizeAttributeValue(attributes['latest-console-version']) : '';
|
|
22
31
|
|
|
32
|
+
if (attributes['page-component-version-is-prerelease'] === 'true') {
|
|
33
|
+
fullVersion = attributes['redpanda-beta-version'] ? sanitizeAttributeValue(attributes['redpanda-beta-version']) : fullVersion;
|
|
34
|
+
}
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const redpandaConsoleVersionRegex = /(\$\{REDPANDA_CONSOLE_VERSION[^\}]*\})/g;
|
|
28
|
-
const fullVersion = asciidoc.attributes['full-version'] ? sanitizeAttributeValue(asciidoc.attributes['full-version']) : '';
|
|
29
|
-
const latestConsoleVersion = asciidoc.attributes['latest-console-version'] ? sanitizeAttributeValue(asciidoc.attributes['latest-console-version']) : '';
|
|
36
|
+
contentString = contentString.replace(redpandaVersionRegex, fullVersion);
|
|
37
|
+
contentString = contentString.replace(redpandaConsoleVersionRegex, latestConsoleVersion);
|
|
38
|
+
}
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
const result = contentString.replace(/\{([\p{Alpha}\d_][\p{Alpha}\d_-]*)\}/gu, (match, name) => {
|
|
41
|
+
if (!(name in attributes)) return match;
|
|
42
|
+
modified = true;
|
|
43
|
+
let value = attributes[name];
|
|
44
|
+
if (value.endsWith('@')) value = value.slice(0, value.length - 1);
|
|
45
|
+
return value;
|
|
46
|
+
});
|
|
34
47
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
48
|
+
if (modified) attachment.contents = Buffer.from(result);
|
|
49
|
+
});
|
|
39
50
|
});
|
|
40
|
-
}
|
|
51
|
+
};
|
|
@@ -7,10 +7,8 @@ module.exports.register = function ({ config }) {
|
|
|
7
7
|
this.on('navigationBuilt', ({ siteCatalog, contentCatalog }) => {
|
|
8
8
|
contentCatalog.getComponents().forEach(({ versions }) => {
|
|
9
9
|
versions.forEach(({ name: component, version, navigation: nav, url: defaultUrl }) => {
|
|
10
|
-
if (component === 'api') return;
|
|
10
|
+
if (component === 'api' || component === 'redpanda-labs') return;
|
|
11
11
|
if (!nav) return;
|
|
12
|
-
const currentComponent = contentCatalog.getComponent(component);
|
|
13
|
-
const prerelease = currentComponent && currentComponent.latestPrerelease ? currentComponent.latestPrerelease : false;
|
|
14
12
|
|
|
15
13
|
const navEntriesByUrl = getNavEntriesByUrl(nav);
|
|
16
14
|
const unlistedPages = contentCatalog
|
|
@@ -30,10 +28,7 @@ module.exports.register = function ({ config }) {
|
|
|
30
28
|
return collector;
|
|
31
29
|
}, []);
|
|
32
30
|
|
|
33
|
-
if (unlistedPages.length &&
|
|
34
|
-
// 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.
|
|
35
|
-
addRedpandaConnectPagesToNav(nav[0].items, unlistedPages);
|
|
36
|
-
} else if (unlistedPages.length && addToNavigation) {
|
|
31
|
+
if (unlistedPages.length && addToNavigation) {
|
|
37
32
|
nav.push({
|
|
38
33
|
content: unlistedPagesHeading,
|
|
39
34
|
items: unlistedPages.map((page) => {
|
|
@@ -55,33 +50,6 @@ function getNavEntriesByUrl(items = [], accum = {}) {
|
|
|
55
50
|
return accum;
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
function addRedpandaConnectPagesToNav(navItems, pages) {
|
|
59
|
-
// get the Components nav section
|
|
60
|
-
let componentsSection = navItems.find(item => item.content === 'Components');
|
|
61
|
-
if (!componentsSection) return;
|
|
62
|
-
|
|
63
|
-
pages.forEach(page => {
|
|
64
|
-
const dirname = page.out.dirname;
|
|
65
|
-
if (!dirname.includes('/components/')) return;
|
|
66
|
-
const heading = page.asciidoc.attributes.doctitle;
|
|
67
|
-
const pathParts = dirname.split('/').slice(2); // Get the type
|
|
68
|
-
// get existing nav items inside the Components tree
|
|
69
|
-
let currentLevel = componentsSection.items;
|
|
70
|
-
|
|
71
|
-
pathParts.forEach((part, index) => {
|
|
72
|
-
const capitalizedPart = part.charAt(0).toUpperCase() + part.slice(1);
|
|
73
|
-
let section = currentLevel.find(item => item.content === capitalizedPart);
|
|
74
|
-
if (!section) {
|
|
75
|
-
section = { content: capitalizedPart, items: [], root: index === 0 };
|
|
76
|
-
currentLevel.push(section);
|
|
77
|
-
}
|
|
78
|
-
currentLevel = section.items;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
currentLevel.push({ content: page.asciidoc.navtitle || page.src.stem, url: page.pub.url, urlType: 'internal' });
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
53
|
function removePageFromNav(navItems, urlToRemove) {
|
|
86
54
|
// Remove the page from the navigation items
|
|
87
55
|
for (let i = navItems.length - 1; i >= 0; i--) {
|
|
@@ -14,14 +14,11 @@ module.exports.register = function () {
|
|
|
14
14
|
pageVersion = page.asciidoc?.attributes['page-component-version'];
|
|
15
15
|
const component = contentCatalog.getComponent(componentName);
|
|
16
16
|
|
|
17
|
-
// Check if the page is part of the beta version
|
|
18
|
-
const isPrerelease = component && pageVersion && component.latestPrerelease && component.latestPrerelease.version === pageVersion;
|
|
19
|
-
|
|
20
17
|
// Check the conditions for unpublishing the page
|
|
21
18
|
const shouldUnpublish = (
|
|
22
19
|
page.asciidoc?.attributes['page-unpublish'] ||
|
|
23
20
|
(page.asciidoc?.attributes['publish-only-during-beta']
|
|
24
|
-
&& !
|
|
21
|
+
&& !page.asciidoc?.attributes['page-component-version-is-prerelease'] // Not part of a beta version, meaning the beta period has ended
|
|
25
22
|
)
|
|
26
23
|
);
|
|
27
24
|
|
|
@@ -30,7 +30,13 @@ module.exports.register = function ({ config }) {
|
|
|
30
30
|
|
|
31
31
|
const components = await contentCatalog.getComponents()
|
|
32
32
|
components.forEach(component => {
|
|
33
|
+
let prerelease = component.latestPrerelease;
|
|
33
34
|
component.versions.forEach(({ name, version, asciidoc }) => {
|
|
35
|
+
// This attribute is used for conditionally rendering content for beta releases.
|
|
36
|
+
// It is also used in the `unpublish-pages` extension to unpublish beta pages that aren't part of a beta version.
|
|
37
|
+
if (prerelease && prerelease.version === version) {
|
|
38
|
+
asciidoc.attributes['page-component-version-is-prerelease'] = 'true'
|
|
39
|
+
}
|
|
34
40
|
if (LatestConsoleVersion) {
|
|
35
41
|
asciidoc.attributes['latest-console-version'] = `${LatestConsoleVersion}@`
|
|
36
42
|
logger.info(`Set Redpanda Console version to ${LatestConsoleVersion} in ${name} ${version}`)
|