@redpanda-data/docs-extensions-and-macros 5.3.4 → 5.3.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.
@@ -86,6 +86,7 @@ IMPORTANT: Extensions must be registered under the `antora.extensions` key in yo
86
86
  * **add-global-attributes** - Add attributes globally to all pages
87
87
  * **add-pages-to-root** - Add pages to the root navigation
88
88
  * **process-context-switcher** - Handle context-dependent content
89
+ * **set-available-attachment-versions** - Point UI templates at the newest generated JSON attachments that exist in the catalog
89
90
  * **validate-attributes** - Validate AsciiDoc attributes
90
91
 
91
92
  === AI-friendly documentation
@@ -456,6 +456,35 @@ antora:
456
456
  - '@redpanda-data/docs-extensions-and-macros/extensions/version-fetcher/set-latest-version'
457
457
  ```
458
458
 
459
+ == Set available attachment versions
460
+
461
+ This extension scans the content catalog for generated JSON attachments and sets attributes that point UI templates at the newest file that actually exists, instead of the newest released version. Release-tracking attributes such as `latest-redpanda-tag` and `latest-connect-version` can be ahead of the newest generated JSON in the catalog; without this extension, the docs-ui `head-meta` partial falls back to a constructed production URL that returns 404 on every page view.
462
+
463
+ It sets the following attributes on component versions (never overwriting a value that is already set, so they can be pinned in `antora.yml`):
464
+
465
+ * `available-properties-tag`: newest `redpanda-properties-<tag>.json` attachment in the `reference` module of each version of the streaming component (`streaming`, or `ROOT` on older branches).
466
+ * `available-connect-version`: newest `connect-<version>.json` attachment in the `components` module of the connect component (`connect`, or `redpanda-connect` on older branches).
467
+ * `page-disable-property-tooltips`: set to `true` on streaming versions that have no properties JSON at all, so browsers never request a URL that cannot exist.
468
+
469
+ === Environment variables
470
+
471
+ This extension does not require any environment variables.
472
+
473
+ === Configuration options
474
+
475
+ There are no configurable options for this extension.
476
+
477
+ === Registration
478
+
479
+ Register the `set-available-attachment-versions` extension in the Antora playbook under the `antora.extensions` key like so:
480
+
481
+ [source,yaml]
482
+ ----
483
+ antora:
484
+ extensions:
485
+ - require: '@redpanda-data/docs-extensions-and-macros/extensions/set-available-attachment-versions'
486
+ ----
487
+
459
488
  == Validate attributes
460
489
 
461
490
  This extension ensures the consistency and validity of page attributes, focusing on validating page categories against a predefined list of valid categories and subcategories. It automatically adds missing parent categories for any specified subcategories and removes any specified categories that are invalid. Additionally, it processes specific environment attributes, setting corresponding page-level attributes when environment conditions are met.
@@ -0,0 +1,105 @@
1
+ 'use strict'
2
+
3
+ const semver = require('semver')
4
+
5
+ /**
6
+ * Points UI templates at generated JSON attachments that actually exist.
7
+ *
8
+ * The docs-ui head-meta partial builds <meta name="properties-json-url"> and
9
+ * <meta name="connect-json-url"> tags from version attributes such as
10
+ * latest-redpanda-tag and latest-connect-version. Those attributes track the
11
+ * newest GitHub release, which can be ahead of the newest generated JSON in
12
+ * the content catalog. When that happens the template's production fallback
13
+ * URL points at a file that does not exist, and every page view requests a
14
+ * guaranteed 404.
15
+ *
16
+ * This extension scans the catalog on contentClassified and sets, per
17
+ * component version:
18
+ *
19
+ * - available-properties-tag: newest redpanda-properties-<tag>.json attachment
20
+ * in the reference module of each streaming (ROOT) component version
21
+ * - available-connect-version: newest connect-<version>.json attachment in the
22
+ * components module of the connect component
23
+ * - page-disable-property-tooltips: 'true' on streaming versions that have no
24
+ * properties JSON at all, so browsers never request a URL that cannot exist
25
+ *
26
+ * Attributes already set (for example, pinned in antora.yml) are never
27
+ * overwritten.
28
+ */
29
+
30
+ const PROPERTIES_COMPONENTS = ['ROOT', 'streaming']
31
+ const CONNECT_COMPONENTS = ['connect', 'redpanda-connect']
32
+
33
+ const PROPERTIES_JSON_RX = /^redpanda-properties-(v\d+\.\d+\.\d+(?:-[\w.]+)?)\.json$/
34
+ const CONNECT_JSON_RX = /^connect-(\d+\.\d+\.\d+(?:-[\w.]+)?)\.json$/
35
+
36
+ module.exports.register = function () {
37
+ const logger = this.getLogger('set-available-attachment-versions-extension')
38
+
39
+ this.once('contentClassified', ({ contentCatalog }) => {
40
+ contentCatalog.getComponents().forEach((component) => {
41
+ const isProperties = PROPERTIES_COMPONENTS.includes(component.name)
42
+ const isConnect = CONNECT_COMPONENTS.includes(component.name)
43
+ if (!isProperties && !isConnect) return
44
+
45
+ component.versions.forEach((compVer) => {
46
+ const attributes = ((compVer.asciidoc = compVer.asciidoc || {}).attributes =
47
+ compVer.asciidoc.attributes || {})
48
+ const attachments = contentCatalog.findBy({
49
+ component: component.name,
50
+ version: compVer.version,
51
+ family: 'attachment',
52
+ })
53
+
54
+ if (isProperties) {
55
+ const newest = findNewestVersion(attachments, 'reference', PROPERTIES_JSON_RX)
56
+ if (newest) {
57
+ if (!attributes['available-properties-tag']) {
58
+ attributes['available-properties-tag'] = newest
59
+ logger.info(
60
+ `Set available-properties-tag=${newest} for ${component.name}@${compVer.version}`
61
+ )
62
+ }
63
+ } else if (attributes['latest-redpanda-tag'] && !attributes['available-properties-tag']) {
64
+ // Tooltips would request a JSON that does not exist for this version
65
+ if (!attributes['page-disable-property-tooltips']) {
66
+ attributes['page-disable-property-tooltips'] = 'true'
67
+ logger.info(
68
+ `No properties JSON found for ${component.name}@${compVer.version}; disabling property tooltips`
69
+ )
70
+ }
71
+ }
72
+ }
73
+
74
+ if (isConnect) {
75
+ const newest = findNewestVersion(attachments, 'components', CONNECT_JSON_RX)
76
+ if (newest && !attributes['available-connect-version']) {
77
+ attributes['available-connect-version'] = newest
78
+ logger.info(
79
+ `Set available-connect-version=${newest} for ${component.name}@${compVer.version}`
80
+ )
81
+ }
82
+ }
83
+ })
84
+ })
85
+ })
86
+ }
87
+
88
+ function findNewestVersion (attachments, module, rx) {
89
+ let newestRaw = null
90
+ let newestSemver = null
91
+ attachments.forEach((attachment) => {
92
+ if (attachment.src.module !== module) return
93
+ const basename = attachment.src.relative.split('/').pop()
94
+ const match = basename.match(rx)
95
+ if (!match) return
96
+ const raw = match[1]
97
+ const parsed = semver.coerce(raw, { includePrerelease: true })
98
+ if (!parsed) return
99
+ if (!newestSemver || semver.gt(parsed, newestSemver)) {
100
+ newestSemver = parsed
101
+ newestRaw = raw
102
+ }
103
+ })
104
+ return newestRaw
105
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "5.3.4",
3
+ "version": "5.3.6",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",
@@ -60,6 +60,7 @@
60
60
  "./extensions/generate-rp-connect-info": "./extensions/generate-rp-connect-info.js",
61
61
  "./extensions/generate-fields-only-pages": "./extensions/generate-fields-only-pages.js",
62
62
  "./extensions/add-global-attributes": "./extensions/add-global-attributes.js",
63
+ "./extensions/set-available-attachment-versions": "./extensions/set-available-attachment-versions.js",
63
64
  "./extensions/git-full-clone": "./extensions/git-full-clone.js",
64
65
  "./extensions/add-git-dates": "./extensions/add-git-dates.js",
65
66
  "./extensions/add-faq-structured-data": "./extensions/add-faq-structured-data.js",