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

twolf pushed a commit to branch dev_3.0
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git


The following commit(s) were added to refs/heads/dev_3.0 by this push:
     new 1209dcc84 [site] Improve links in japicmp reports
1209dcc84 is described below

commit 1209dcc8446ac39c2c3eb3e75f11a3bfc4ce0261
Author: Thomas Wolf <tw...@apache.org>
AuthorDate: Wed Apr 23 14:25:19 2025 +0200

    [site] Improve links in japicmp reports
    
    japicmp generates links without href; doxia gives them href="#null".
    Post-process the HTML to supply known anchors if we can determine them.
    
    This enables links between classes referenced in the same japicmp
    report.
---
 sshd-site/src/main/groovy/alerts.groovy | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/sshd-site/src/main/groovy/alerts.groovy 
b/sshd-site/src/main/groovy/alerts.groovy
index 7aaf72cfd..4cdd3f22d 100644
--- a/sshd-site/src/main/groovy/alerts.groovy
+++ b/sshd-site/src/main/groovy/alerts.groovy
@@ -35,11 +35,19 @@ def warning_class = "alert-warning"
 def warning_img = "<svg class='${warning_class}' viewBox='0 0 16 16' 
version='1.1' width='16' height='16'><path d='M6.457 1.047c.659-1.234 
2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 
1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 
.22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 
0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z' /></svg>"
 
 def replace(text, mark, css, img, label) {
-    return text.replaceAll("<blockquote>(\\R|\\S)*<p>\\Q${mark}\\E", 
"<blockquote class='${css}'><p class='${css}'>${img}${label}")
+    return text.replaceAll("<blockquote>(\\R|\\s)*<p>\\Q${mark}\\E", 
"<blockquote class='${css}'><p class='${css}'>${img}${label}")
 }
 
 def reports = new File("${project.build.directory}/site").listFiles()
 
+def findAnchors(text) {
+  def set = [] as Set
+  text.findAll("<a\\s+id=\"user-content-([\\w.]+)\"") { match, pkg ->
+    set.add(pkg)
+  }
+  return set
+}
+
 reports.each() { file ->
   def name = file.name
   if (name.startsWith("japicmp-")) {
@@ -50,6 +58,16 @@ reports.each() { file ->
     content = replace(content, "[!NOTE]", note_class, note_img, "Note")
     content = replace(content, "[!TIP]", tip_class, tip_img, "Tip")
     content = replace(content, "[!WARNING]", warning_class, warning_img, 
"Warning")
+    log.info("Fixing links in ${name}")
+    def anchors = findAnchors(content)
+    content = content.replaceAll(/href="#null" title="([\w.]+)"/, { all, pkg ->
+      def hash = pkg.toLowerCase()
+      if (anchors.contains(hash)) {
+        return "href=\"#user-content-${hash}\" title=\"${pkg}\""
+      } else {
+        return all
+      }
+    })
     file.text = content
   }
 }

Reply via email to