@redpanda-data/docs-extensions-and-macros 3.0.16 → 3.0.17

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.
@@ -6,72 +6,91 @@
6
6
 
7
7
  module.exports.register = function ({ config }) {
8
8
  const logger = this.getLogger('term-aggregation-extension');
9
- const chalk = require('chalk')
9
+ const chalk = require('chalk');
10
+
11
+ function processTermContent(termContent) {
12
+ const hoverTextMatch = termContent.match(/:hover-text: (.*)/);
13
+ const hoverText = hoverTextMatch ? hoverTextMatch[1] : '';
14
+ if (hoverText && !termContent.includes('{hover-text}')) {
15
+ const firstNewlineIndex = termContent.indexOf('\n\n');
16
+ termContent = firstNewlineIndex !== -1
17
+ ? termContent.slice(0, firstNewlineIndex + 1) + hoverText + '\n' + termContent.slice(firstNewlineIndex + 1)
18
+ : termContent += '\n' + hoverText;
19
+ }
20
+
21
+ const linkMatch = termContent.match(/:link: (.*)/);
22
+ const link = linkMatch ? linkMatch[1] : '';
23
+ if (link) {
24
+ termContent += `\n\nFor more details, see ${link}`;
25
+ }
26
+
27
+ return termContent;
28
+ }
10
29
 
11
30
  this.on('contentAggregated', ({ siteCatalog, contentAggregate }) => {
12
31
  try {
32
+ siteCatalog.termsByCategory = {};
33
+
13
34
  for (const component of contentAggregate) {
14
35
  if (component.name === 'shared') {
15
36
  const termFiles = component.files.filter(file => file.path.includes('modules/terms/partials/'));
16
- siteCatalog.terms = {}
37
+
17
38
  termFiles.forEach(file => {
18
39
  const termContent = file.contents.toString('utf8');
19
- siteCatalog.terms[file.basename] = termContent;
40
+ const categoryMatch = /:category: (.*)/.exec(termContent);
41
+ var category = categoryMatch ? categoryMatch[1] : 'Miscellaneous'; // Default category
42
+
43
+ category = category.charAt(0).toUpperCase() + category.slice(1);
44
+
45
+ if (!siteCatalog.termsByCategory[category]) {
46
+ siteCatalog.termsByCategory[category] = [];
47
+ }
48
+
49
+ siteCatalog.termsByCategory[category].push({ name: file.basename, content: termContent });
20
50
  });
21
- console.log(chalk.green('Loaded terms from shared component.'));
22
- break
51
+
52
+ console.log(chalk.green('Categorized terms from shared component.'));
53
+ break;
23
54
  }
24
55
  }
25
56
  } catch (error) {
26
- logger.error(`Error loading terms: ${error.message}`);
57
+ logger.error(`Error categorizing terms: ${error.message}`);
27
58
  }
28
59
  })
29
60
 
30
61
  .on('contentClassified', ({ siteCatalog, contentCatalog }) => {
31
- const components = contentCatalog.getComponents()
62
+ const components = contentCatalog.getComponents();
32
63
  try {
33
- for (const { versions } of components) {
34
- for (const { name: component, version, asciidoc, title } of versions) {
35
- if (component == 'shared') continue;
36
- const glossaryPage = contentCatalog.resolvePage(`${version?version +'@':''}${component}:reference:glossary.adoc`);
64
+ components.forEach(({ versions }) => {
65
+ versions.forEach(({ name: component, version, asciidoc, title }) => {
66
+ if (component == 'shared') return;
67
+
68
+ const glossaryPage = contentCatalog.resolvePage(`${version ? version + '@' : ''}${component}:reference:glossary.adoc`);
69
+
37
70
  if (glossaryPage) {
38
- asciidoc.attributes['glossary-page'] = 'reference:glossary.adoc'
39
- const glossaryContent = glossaryPage.contents.toString('utf8');
40
- let newContent = glossaryContent;
41
- const sortedTerms = Object.keys(siteCatalog.terms).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
42
- for (i = 0; i < sortedTerms.length; i++) {
43
- const termName = sortedTerms[i];
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
- }
63
- newContent += '\n\n' + termContent;
64
- }
65
- glossaryPage.contents = Buffer.from(newContent, 'utf8');
71
+ asciidoc.attributes['glossary-page'] = 'reference:glossary.adoc';
72
+ let glossaryContent = glossaryPage.contents.toString('utf8');
66
73
 
67
- console.log(chalk.green(`Merged terms into glossary for ${component} component${version? version: ''}.`));
74
+ Object.keys(siteCatalog.termsByCategory).sort().forEach(category => {
75
+ let categoryContent = `\n\n== ${category}\n`;
76
+
77
+ siteCatalog.termsByCategory[category].sort((a, b) => a.name.localeCompare(b.name)).forEach(term => {
78
+ let processedContent = processTermContent(term.content);
79
+ categoryContent += `\n\n${processedContent}`;
80
+ });
81
+
82
+ glossaryContent += categoryContent;
83
+ });
84
+
85
+ glossaryPage.contents = Buffer.from(glossaryContent, 'utf8');
86
+ console.log(chalk.green(`Merged terms into glossary for ${component} component${version ? ' version ' + version : ''}.`));
68
87
  } else {
69
- logger.info(`Skipping ${title} ${version} - No glossary page (reference:glossary.adoc) found`)
88
+ logger.info(`Skipping ${title} ${version ? ' version ' + version : ''} - No glossary page (reference:glossary.adoc) found`);
70
89
  }
71
- }
72
- }
90
+ });
91
+ });
73
92
  } catch (error) {
74
93
  logger.error(`Error merging terms: ${error.message}`);
75
94
  }
76
95
  });
77
- }
96
+ };
@@ -49,6 +49,7 @@ module.exports.register = function (registry, config = {}) {
49
49
  const termObject = {
50
50
  term: attributes['term-name'],
51
51
  def: attributes['hover-text'],
52
+ category: attributes['category'] || '',
52
53
  content
53
54
  }
54
55
 
@@ -115,7 +116,7 @@ module.exports.register = function (registry, config = {}) {
115
116
  definition = attributes.definition;
116
117
  }
117
118
  if (definition) {
118
- logTerms && console.log(`${term}:: ${definition}`)
119
+ logTerms && console.log(`${term}:: ${definition}`)
119
120
  } else if (tooltip) {
120
121
  definition = `${term} not yet defined`
121
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "3.0.16",
3
+ "version": "3.0.17",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",