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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-website.git


The following commit(s) were added to refs/heads/main by this push:
     new be991e94 chore: point links between website pages and blog posts at 
their Markdown mirror
be991e94 is described below

commit be991e94237916c7c08e5b7ff73dbd5919c718e5
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Sep 18 20:32:36 2026 +0200

    chore: point links between website pages and blog posts at their Markdown 
mirror
    
    Hugo pages link to each other by directory (../camel-dna/, /blog/2026/07/
    some-post/), so a reader of the Markdown mirror following such a link
    got the HTML page. Like the .html links that are already rewritten to
    .md, a directory link now gets index.md appended when that page has a
    mirror; links to list pages, redirects and external sites are left alone.
    
    Closes #1779
---
 gulp/helpers/convert-page.js    | 29 ++++++++++++++++++++++++++++-
 gulp/tasks/generate-markdown.js | 14 +++++++++++++-
 test/convert-page-test.js       | 23 +++++++++++++++++++++++
 3 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/gulp/helpers/convert-page.js b/gulp/helpers/convert-page.js
index ac593aae..d5cb6077 100644
--- a/gulp/helpers/convert-page.js
+++ b/gulp/helpers/convert-page.js
@@ -96,4 +96,31 @@ function trimBlogPost(article) {
   }
 }
 
-module.exports = { convertPage };
+/**
+ * Points links at other website pages and blog posts to their Markdown 
mirror. Hugo pages link
+ * to each other by directory (`../camel-dna/`, 
`/blog/2026/07/some-post/#section`); where that
+ * page has a mirror, the link gets `index.md` appended so a reader stays in 
Markdown, like the
+ * `.html` links that convertPage already rewrites to `.md`.
+ *
+ * @param {string} markdown the converted page
+ * @param {string} pagePath site-relative path of this page's Markdown, e.g. 
/trust/index.md
+ * @param {(path: string) => boolean} hasMirror whether a site-relative 
Markdown path exists
+ * @returns {string} the Markdown with the links rewritten
+ */
+function rewriteDirectoryLinks(markdown, pagePath, hasMirror) {
+  const site = 'https://camel.apache.org';
+  return markdown.replace(/\]\(([^)\s]*\/)(#[^)\s]*)?\)/g, (match, target, 
fragment = '') => {
+    let resolved;
+    try {
+      resolved = new URL(target, site + pagePath);
+    } catch {
+      return match;
+    }
+    if (resolved.origin !== site || 
!hasMirror(`${resolved.pathname}index.md`)) {
+      return match;
+    }
+    return `](${target}index.md${fragment})`;
+  });
+}
+
+module.exports = { convertPage, rewriteDirectoryLinks };
diff --git a/gulp/tasks/generate-markdown.js b/gulp/tasks/generate-markdown.js
index de3aa02e..ecac0d1f 100644
--- a/gulp/tasks/generate-markdown.js
+++ b/gulp/tasks/generate-markdown.js
@@ -1,5 +1,5 @@
 const fs = require('fs');
-const { convertPage } = require('../helpers/convert-page');
+const { convertPage, rewriteDirectoryLinks } = 
require('../helpers/convert-page');
 const { createTurndownService } = require('../helpers/turndown-config');
 const { generateToonSitemaps } = require('../helpers/toon-format');
 const { generateLlmsTxt } = require('../helpers/llms-txt');
@@ -82,6 +82,18 @@ async function generateMarkdown() {
 
   console.log(`\nSuccessfully generated ${processedCount} Markdown files`);
 
+  // Website pages and blog posts link to each other by directory; now that 
every mirror is
+  // written, point such links at the mirror where there is one
+  const mirrors = new Set(processedPages);
+  for (const urlPath of processedPages.filter(p => p.endsWith('/index.md'))) {
+    const mdFile = `public${urlPath}`;
+    const markdown = fs.readFileSync(mdFile, 'utf8');
+    const rewritten = rewriteDirectoryLinks(markdown, urlPath, p => 
mirrors.has(p));
+    if (rewritten !== markdown) {
+      fs.writeFileSync(mdFile, rewritten, 'utf8');
+    }
+  }
+
   // Generate llms.txt file
   generateLlmsTxt(processedPages);
 
diff --git a/test/convert-page-test.js b/test/convert-page-test.js
index fbd86010..7477dba2 100644
--- a/test/convert-page-test.js
+++ b/test/convert-page-test.js
@@ -147,3 +147,26 @@ test('a blog post without the rail details still 
converts', () => {
 
   assert.equal(convertPage(html, createTurndownService()).markdown, '# 
Bare\n\nBody.')
 })
+
+const { rewriteDirectoryLinks } = require('../gulp/helpers/convert-page')
+
+test('directory links to pages that have a Markdown mirror get index.md 
appended', () => {
+  const mirrors = new Set(['/camel-dna/index.md', 
'/blog/2026/07/some-post/index.md', '/trust/index.md'])
+  const markdown = 'See [Camel DNA](../camel-dna/), [a 
post](/blog/2026/07/some-post/#section), ' +
+    '[Why Camel](https://camel.apache.org/trust/), [downloads](../download/), 
' +
+    '[docs](../manual/getting-started.md), [external](https://kaoto.io/) and 
![img](../img/x.png).'
+
+  assert.equal(rewriteDirectoryLinks(markdown, 
'/what-is-apache-camel/index.md', p => mirrors.has(p)),
+    'See [Camel DNA](../camel-dna/index.md), [a 
post](/blog/2026/07/some-post/index.md#section), ' +
+    '[Why Camel](https://camel.apache.org/trust/index.md), 
[downloads](../download/), ' +
+    '[docs](../manual/getting-started.md), [external](https://kaoto.io/) and 
![img](../img/x.png).')
+})
+
+test('directory links resolve relative to the page that carries them', () => {
+  const mirrors = new Set(['/blog/2026/07/other/index.md'])
+
+  assert.equal(rewriteDirectoryLinks('[other](../other/)', 
'/blog/2026/07/this/index.md', p => mirrors.has(p)),
+    '[other](../other/index.md)')
+  assert.equal(rewriteDirectoryLinks('[other](../other/)', 
'/blog/2026/08/this/index.md', p => mirrors.has(p)),
+    '[other](../other/)')
+})

Reply via email to