@redpanda-data/docs-extensions-and-macros 3.0.2 → 3.0.4

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
@@ -132,9 +132,9 @@ antora:
132
132
 
133
133
  This extension aggregates all term pages from the {url-playbook}[`shared` component] and does the following:
134
134
 
135
- - Makes all `term-name` and `hover-text` attributes available to the <<glossterm-macro,`glossterm` macro>>.
135
+ - Makes all `term-name`, `hover-text`, and `link` attributes available to the <<glossterm-macro,`glossterm` macro>>.
136
136
  - Looks for glossary pages named `reference:glossary.adoc` in all versions of all components and appends the contents of each term file to the glossary in alphabetical order.
137
- - If a glossary page is found, sets the `glossary-page` attribute of the <<glossterm, `glossterm` macro>> to `reference:glossary.adoc`.
137
+ - If a glossary page is found, sets the `glossary-page` attribute of the <<glossterm, `glossterm` macro>> to `reference:glossary.adoc` so that terms can be linked to the glossary page.
138
138
 
139
139
  ==== Registration example
140
140
 
@@ -41,19 +41,37 @@ module.exports.register = function ({ config }) {
41
41
  const sortedTerms = Object.keys(siteCatalog.terms).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
42
42
  for (i = 0; i < sortedTerms.length; i++) {
43
43
  const termName = sortedTerms[i];
44
- const termContent = siteCatalog.terms[termName];
44
+ let termContent = siteCatalog.terms[termName];
45
+ const hoverTextMatch = termContent.match(/:hover-text: (.*)/);
46
+ const hoverText = hoverTextMatch ? hoverTextMatch[1] : '';
47
+ const linkMatch = termContent.match(/:link: (.*)/);
48
+ const link = linkMatch ? linkMatch[1] : '';
49
+ // If the hover-text attribute is found and the content does not already contain {hover-text}, append it as a new line after the first newline
50
+ if (hoverText && !termContent.includes('{hover-text}')) {
51
+ const firstNewlineIndex = termContent.indexOf('\n\n');
52
+ if (firstNewlineIndex !== -1) {
53
+ termContent = termContent.slice(0, firstNewlineIndex + 1) + hoverText + '\n' + termContent.slice(firstNewlineIndex + 1);
54
+ } else {
55
+ // If there's no newline, just append at the end
56
+ termContent += '\n' + hoverText;
57
+ }
58
+ }
59
+ // If the link attribute is found, append it at the end of the term content
60
+ if (link) {
61
+ termContent += `\n\nFor more details, see ${link}`;
62
+ }
45
63
  newContent += '\n\n' + termContent;
46
64
  }
47
65
  glossaryPage.contents = Buffer.from(newContent, 'utf8');
48
66
 
49
- console.log(chalk.green(`Transposed terms into glossary for ${component}.`));
67
+ console.log(chalk.green(`Merged terms into glossary for ${component} component${version? version: ''}.`));
50
68
  } else {
51
69
  logger.warn(`Skipping ${title} ${version} - No glossary page (reference:glossary.adoc) found`)
52
70
  }
53
71
  }
54
72
  }
55
73
  } catch (error) {
56
- logger.error(`Error transposing terms: ${error.message}`);
74
+ logger.error(`Error merging terms: ${error.message}`);
57
75
  }
58
76
  });
59
77
  }
@@ -22,7 +22,6 @@ const chalk = require('chalk')
22
22
  * @returns {SearchIndexData} A data object that contains the Algolia index
23
23
  */
24
24
  function generateIndex (playbook, contentCatalog, { indexLatestOnly = false, excludes = [], logger } = {}) {
25
- if (!process.env.ALGOLIA_ADMIN_API_KEY || !process.env.ALGOLIA_APP_ID || !process.env.ALGOLIA_INDEX_NAME) return
26
25
  if (!logger) logger = process.env.NODE_ENV === 'test' ? { info: () => undefined } : console
27
26
 
28
27
  const algolia = {}
@@ -23,6 +23,8 @@ module.exports.register = function (registry, config = {}) {
23
23
  // Extract the term definitions from the files
24
24
  const ATTRIBUTE_REGEX = /^:([a-zA-Z0-9_-]+):[ \t]*(.*)$/gm
25
25
 
26
+ const termMap = new Map();
27
+
26
28
  const terms = termFiles.map(file => {
27
29
  const content = file.contents.toString()
28
30
  const attributes = {}
@@ -34,15 +36,27 @@ module.exports.register = function (registry, config = {}) {
34
36
  }
35
37
 
36
38
  if (!attributes['term-name'] || !attributes['hover-text']) {
37
- console.warn(`Skipping file ${file.path} due to missing 'term-name' and/or 'hover-text'.`)
39
+ console.warn(`Skipping term ${file.path} due to missing 'term-name' and/or 'hover-text attributes'.`)
38
40
  return null
39
41
  }
40
42
 
41
- return {
43
+ if (termMap.has(attributes['term-name'])) {
44
+ throw new Error(`Error: Duplicate term-name '${attributes['term-name']}' found in ${file.src.fileUri || file.src.editUrl}.`);
45
+ }
46
+
47
+ termMap.set(attributes['term-name'], true);
48
+
49
+ const termObject = {
42
50
  term: attributes['term-name'],
43
51
  def: attributes['hover-text'],
44
52
  content
45
53
  }
54
+
55
+ if (attributes['link'] && attributes['link'].trim() !== '') {
56
+ termObject.link = attributes['link']
57
+ }
58
+
59
+ return termObject
46
60
  }).filter(Boolean)
47
61
 
48
62
  // Store the terms in the cache
@@ -81,9 +95,11 @@ module.exports.register = function (registry, config = {}) {
81
95
  const term = attributes.term || target
82
96
  const document = parent.document
83
97
  const context = vfs.getContext()
84
- const localTerms = document.getAttribute("local-terms") || [];
85
- const localTermData = (localTerms || []).find((t) => t.term === term) || {};
86
- const customLink = localTermData.link;
98
+ const customLinkCandidate = context.gloss.find(candidate => 'link' in candidate && candidate.term === term);
99
+ let customLink;
100
+ if (customLinkCandidate) {
101
+ customLink = customLinkCandidate.link;
102
+ }
87
103
  var tooltip = document.getAttribute('glossary-tooltip')
88
104
  if (tooltip === 'true') tooltip = 'data-glossary-tooltip'
89
105
  if (tooltip && tooltip !== 'title' && !tooltip.startsWith('data-')) {
@@ -96,7 +112,7 @@ module.exports.register = function (registry, config = {}) {
96
112
  if (index >= 0) {
97
113
  definition = context.gloss[index].def
98
114
  } else {
99
- definition = localTermData.definition || attributes.definition;
115
+ definition = attributes.definition;
100
116
  }
101
117
  if (definition) {
102
118
  logTerms && console.log(`${term}:: ${definition}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",