This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new cb0d535a4 Fix API_DOCS variable replacement in CI build
cb0d535a4 is described below

commit cb0d535a4bd1738adb225ee09ab2e82e1fdbc85b
Author: James Bognar <[email protected]>
AuthorDate: Tue Sep 23 09:27:41 2025 -0400

    Fix API_DOCS variable replacement in CI build
    
    - Enhanced remark-version-replacer plugin to handle more node types
    - Added string-level replacement as fallback mechanism
    - Process MDX JSX elements and HTML nodes
    - Should resolve 'API_DOCS is not defined' error in GitHub Actions
---
 .../src/plugins/remark-version-replacer.js         | 74 +++++++++++++++++-----
 1 file changed, 59 insertions(+), 15 deletions(-)

diff --git a/juneau-docs-poc/src/plugins/remark-version-replacer.js 
b/juneau-docs-poc/src/plugins/remark-version-replacer.js
index 4fb583231..7891c825a 100644
--- a/juneau-docs-poc/src/plugins/remark-version-replacer.js
+++ b/juneau-docs-poc/src/plugins/remark-version-replacer.js
@@ -13,6 +13,15 @@
 
 const { visit } = require('unist-util-visit');
 
+/**
+ * Simple string replacement function as fallback
+ */
+function replaceInString(content, version, apiDocsUrl) {
+  return content
+    .replace(/\{\{JUNEAU_VERSION\}\}/g, version)
+    .replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
+}
+
 /**
  * Remark plugin to replace version and API docs placeholders with actual 
values.
  * This works inside code blocks and anywhere else in the markdown.
@@ -21,29 +30,64 @@ function remarkVersionReplacer(options = {}) {
   const version = options.version || '9.0.1';
   const apiDocsUrl = options.apiDocsUrl || '../apidocs';
   
-  return (tree) => {
-    visit(tree, ['text', 'code'], (node) => {
-      if (node.value) {
-        // Replace {{JUNEAU_VERSION}} with the actual version
+  return (tree, file) => {
+    // First, do a string-level replacement on the entire file content
+    if (file.contents) {
+      file.contents = replaceInString(file.contents, version, apiDocsUrl);
+    }
+    // Process all nodes that might contain text content
+    visit(tree, (node) => {
+      // Handle text nodes
+      if (node.type === 'text' && node.value) {
         node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
-        // Replace {{API_DOCS}} with the actual API docs URL
         node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
       }
-    });
-    
-    visit(tree, 'code', (node) => {
-      if (node.value) {
-        // Also handle code blocks specifically
+      
+      // Handle code nodes
+      if (node.type === 'code' && node.value) {
         node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
         node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
       }
-    });
-
-    // Handle link nodes specifically for API docs replacements
-    visit(tree, 'link', (node) => {
-      if (node.url) {
+      
+      // Handle inline code nodes
+      if (node.type === 'inlineCode' && node.value) {
+        node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
+        node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
+      }
+      
+      // Handle link nodes
+      if (node.type === 'link' && node.url) {
         node.url = node.url.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
       }
+      
+      // Handle HTML/JSX nodes (like our custom components)
+      if (node.type === 'html' && node.value) {
+        node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
+        node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
+      }
+      
+      // Handle MDX JSX elements
+      if (node.type === 'mdxJsxTextElement' || node.type === 
'mdxJsxFlowElement') {
+        // Process children of JSX elements
+        if (node.children) {
+          node.children.forEach(child => {
+            if (child.type === 'text' && child.value) {
+              child.value = child.value.replace(/\{\{JUNEAU_VERSION\}\}/g, 
version);
+              child.value = child.value.replace(/\{\{API_DOCS\}\}/g, 
apiDocsUrl);
+            }
+          });
+        }
+        
+        // Process attributes
+        if (node.attributes) {
+          node.attributes.forEach(attr => {
+            if (attr.value && typeof attr.value === 'string') {
+              attr.value = attr.value.replace(/\{\{JUNEAU_VERSION\}\}/g, 
version);
+              attr.value = attr.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
+            }
+          });
+        }
+      }
     });
   };
 }

Reply via email to