@redpanda-data/docs-extensions-and-macros 3.2.3 → 3.2.5

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 CHANGED
@@ -180,6 +180,27 @@ antora:
180
180
  - require: '@redpanda-data/docs-extensions-and-macros/extensions/add-global-attributes'
181
181
  ```
182
182
 
183
+ === Modify redirects file
184
+
185
+ This extension removes redundant redirects from the Netlify redirects file. The need for this extension arises from an issue where the use of the `indexify` feature in Antora, combined with page aliases, can inadvertently create redirect loops or redundant redirects where the source and target URLs are identical.
186
+
187
+ The issue is https://antora.zulipchat.com/#narrow/stream/282400-users/topic/Redirect.20Loop.20Issue.20with.20Page.20Renaming.20and.20Indexify/near/433691700[recognized as a bug] within Antora's redirect producer, which does not currently
188
+ check if the source and target URLs are the same before creating a redirect.
189
+
190
+ The purpose of this script is to scan the `_redirects` file and remove any entries that point
191
+ a URL to itself, which not only prevents redirect loops but also optimizes the redirect process
192
+ by eliminating unnecessary entries. This cleanup helps ensure that the redirects file only contains valid and useful redirection rules.
193
+
194
+ By integrating this script into the Antora pipeline, we ensure that each build's output is optimized and free from potential issues related to improper redirects, enhancing both site performance and user experience.
195
+
196
+ ==== Registration example
197
+
198
+ ```yaml
199
+ antora:
200
+ extensions:
201
+ - '@redpanda-data/docs-extensions-and-macros/extensions/modify-redirects'
202
+ ```
203
+
183
204
  === Replace attributes in attachments
184
205
 
185
206
  This extension replaces AsciiDoc attribute placeholders with their respective values in attachment files, such as CSS, HTML, and YAML.
@@ -77,7 +77,7 @@ function generateIndex (playbook, contentCatalog, { indexLatestOnly = false, exc
77
77
 
78
78
  // capture the component name and version
79
79
  const cname = component.name
80
- const version = page.src.prerelease ? page.src.displayVersion : page.src.version;
80
+ const version = page.src.origin.descriptor.prerelease ? page.src.origin.descriptor.displayVersion : page.src.version;
81
81
 
82
82
  // handle the page keywords
83
83
  const kw = root.querySelector('meta[name=keywords]')
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ function redirectModifier(files, outputDir, logger) {
7
+ files.forEach((file) => {
8
+ const filePath = path.join(outputDir, file);
9
+ if (!fs.existsSync(filePath)) return
10
+ let content = fs.readFileSync(filePath, 'utf8');
11
+ const lines = content.split('\n');
12
+
13
+ // Filter out redirects that point to themselves
14
+ const modifiedLines = lines.filter((line) => {
15
+ const parts = line.split(' ');
16
+ if (parts[0] == parts[1]) logger.info(`Removed redirect that points to itself: ${line}`)
17
+ return parts[0] !== parts[1]; // Ensure the source and target are not the same
18
+ });
19
+
20
+ // Join the array back into a string and write it back to the file
21
+ const modifiedContent = modifiedLines.join('\n');
22
+ fs.writeFileSync(filePath, modifiedContent, 'utf8');
23
+ logger.info(`Processed and updated redirects in ${filePath}`);
24
+ })
25
+ }
26
+
27
+ module.exports.register = function ({ config }) {
28
+ const logger = this.getLogger('redirects-produced');
29
+ this.on('sitePublished', async ({ publications }) => {
30
+ publications.forEach(publication => {
31
+ const outputDir = publication.resolvedPath;
32
+ const redirectFile = ['_redirects'];
33
+ redirectModifier(redirectFile, outputDir, logger);
34
+ });
35
+ });
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "3.2.3",
3
+ "version": "3.2.5",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",
@@ -35,6 +35,7 @@
35
35
  "./extensions/validate-attributes": "./extensions/validate-attributes.js",
36
36
  "./extensions/find-related-docs": "./extensions/find-related-docs.js",
37
37
  "./extensions/find-related-labs": "./extensions/find-related-labs.js",
38
+ "./extensions/modify-redirects": "./extensions/modify-redirects.js",
38
39
  "./extensions/algolia-indexer/index": "./extensions/algolia-indexer/index.js",
39
40
  "./extensions/aggregate-terms": "./extensions/aggregate-terms.js",
40
41
  "./macros/glossary": "./macros/glossary.js",