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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9c8295dc542 Load railroad diagrams via same-domain hash path (#37617)
9c8295dc542 is described below

commit 9c8295dc542a33878f92e67f1f44257de97e23a9
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Jan 2 11:57:33 2026 +0800

    Load railroad diagrams via same-domain hash path (#37617)
---
 .../themes/hugo-theme-learn/static/js/learn.js     | 101 ++++++++++++---------
 1 file changed, 57 insertions(+), 44 deletions(-)

diff --git a/docs/document/themes/hugo-theme-learn/static/js/learn.js 
b/docs/document/themes/hugo-theme-learn/static/js/learn.js
index 2b1881f470f..7f7c3bc5534 100644
--- a/docs/document/themes/hugo-theme-learn/static/js/learn.js
+++ b/docs/document/themes/hugo-theme-learn/static/js/learn.js
@@ -402,56 +402,69 @@ jQuery(document).ready(function() {
 
 
     //railroad diagram
-    
-    if($('.tab-panel').length) {
-        var codeStr = $('.tab-panel code').text()
-        var _h = $('.tab-panel code').height()
-        var diagram = $('#diagram')
-
-        function appendFormElement(tagName, type, name, value, parentEl){
-            var el = document.createElement(tagName)
-            el.type = type
-            el.name = name
-            el.value = value,
-            parentEl.appendChild(el)
-        }
-
-        var form = document.createElement('form')
-        form.name = "data2"
-        form.method = "post"
-        form.action = "https://www.sphere-ex.com/rrdg";
-        form.enctype="multipart/form-data"
-
-        appendFormElement('input', 'hidden', 'task', 'VIEW', form)
-        appendFormElement('input', 'hidden', 'frame', '', form)
-        appendFormElement('input', 'hidden', 'name', 'ui', form)
-        
-        // 可增加
-        appendFormElement('input', 'hidden', 'color', '#FF8B00', form)
-
-        appendFormElement('textarea', 'hidden', 'text', codeStr, form)
-     
-        appendFormElement('input', 'hidden', 'width', '700', form)
-        appendFormElement('input', 'hidden', 'padding', '10', form)
-        appendFormElement('input', 'hidden', 'strokewidth', '1', form)
+    if ($('.tab-panel').length) {
+        var codeBlock = $('.tab-panel code').first();
+        var diagram = $('#diagram');
+        var grammarText = codeBlock.text() || '';
+
+        if (grammarText && diagram.length) {
+            var loadingId = 'rr-loading';
+            diagram.before('<p id="' + loadingId + '">Loading ...</p>');
+
+            function baseRailroadPath() {
+                var parts = window.location.pathname.split('/');
+                var docIdx = parts.indexOf('document');
+                if (docIdx === -1) {
+                    return '/railroad/';
+                }
+                // e.g. /document/current/... -> /document/current/railroad/
+                return '/' + parts.slice(1, docIdx + 2).join('/') + 
'/railroad/';
+            }
 
-        document.body.appendChild(form)
+            function toHex(buffer) {
+                var bytes = new Uint8Array(buffer);
+                var hex = '';
+                for (var i = 0; i < bytes.length; i++) {
+                    hex += ('00' + bytes[i].toString(16)).slice(-2);
+                }
+                return hex;
+            }
 
-        document.forms.data2.target = 'diagram';
-        document.forms.data2.frame.value = 'diagram';
-        // document.forms.data2.time.value = new Date().getTime();
+            function sha256(text) {
+                if (!window.crypto || !window.crypto.subtle || 
!window.TextEncoder) {
+                    return Promise.reject(new Error('SHA-256 unsupported'));
+                }
+                var encoder = new TextEncoder();
+                return window.crypto.subtle.digest('SHA-256', 
encoder.encode(text)).then(toHex);
+            }
 
-        
-        diagram.before('<p id="testLoading">Loading ...</p>')
+            sha256(grammarText).then(function (hash) {
+                var paths = [baseRailroadPath(), '/railroad/'];
+                var idx = 0;
 
-        document.forms.data2.submit();
+                function loadNext() {
+                    if (idx >= paths.length) {
+                        $('#' + loadingId).text('Railroad diagram 
unavailable.');
+                        return;
+                    }
+                    var src = paths[idx] + hash + '.html';
+                    diagram.attr('src', src);
+                }
 
-        document.body.removeChild(form)
+                diagram.on('load', function () {
+                    $('#' + loadingId).remove();
+                    var codeHeight = codeBlock.height();
+                    diagram.height(codeHeight > 500 ? codeHeight + 'px' : 
'500px');
+                }).on('error', function () {
+                    idx += 1;
+                    loadNext();
+                });
 
-        diagram.on('load', function(){
-            $('#testLoading').remove()
-            diagram.height(_h > 500 ? _h+'px' : '500px')
-        })
+                loadNext();
+            }).catch(function () {
+                $('#' + loadingId).text('Railroad diagram unavailable.');
+            });
+        }
     }
 
 });

Reply via email to