summaryrefslogtreecommitdiff
path: root/sysret.org/themes/tabi-lean/static/js/codeBlockNameLinks.js
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2025-09-13 15:01:06 -0600
committerAlejandro Soto <alejandro@34project.org>2025-09-13 15:01:06 -0600
commitf4fcda54638685899c730b3fa90a87d80d6dbef5 (patch)
tree0737e627cce304c3a9c4e757bc5f6571a7456091 /sysret.org/themes/tabi-lean/static/js/codeBlockNameLinks.js
parentd8b9cf1f61cc07d625f1c37ccc28adfd58918416 (diff)
parent2c13119932765c6d788f08fb53abc244407c0d80 (diff)
Merge commit '6a7d3111b31e73fc66af5360149d41f690fbcaa4'
Diffstat (limited to '')
-rw-r--r--sysret.org/themes/tabi-lean/static/js/codeBlockNameLinks.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/sysret.org/themes/tabi-lean/static/js/codeBlockNameLinks.js b/sysret.org/themes/tabi-lean/static/js/codeBlockNameLinks.js
new file mode 100644
index 0000000..ea0b678
--- /dev/null
+++ b/sysret.org/themes/tabi-lean/static/js/codeBlockNameLinks.js
@@ -0,0 +1,36 @@
+document.addEventListener("DOMContentLoaded", function() {
+ // Convert URLs in data-name to links.
+ document.querySelectorAll('code[data-name]').forEach(function(code) {
+ const name = code.getAttribute('data-name');
+ if (name.startsWith('http')) {
+ const link = document.createElement('a');
+ link.href = name;
+ link.className = 'source-path';
+ link.textContent = name;
+ code.insertBefore(link, code.firstChild);
+ // Remove data-name to avoid overlap with Zola's native display.
+ code.removeAttribute('data-name');
+ code.parentElement?.removeAttribute('data-name');
+ }
+ });
+
+ // Legacy support for old shortcode. https://github.com/welpo/tabi/pull/489
+ document.querySelectorAll('.code-source').forEach(function(marker) {
+ const sourceUrl = marker.getAttribute('data-source');
+ const nextPre = marker.nextElementSibling;
+ if (nextPre?.tagName === 'PRE') {
+ const code = nextPre.querySelector('code');
+ if (code) {
+ if (sourceUrl.startsWith('http')) {
+ const link = document.createElement('a');
+ link.href = sourceUrl;
+ link.className = 'source-path';
+ link.textContent = sourceUrl;
+ code.insertBefore(link, code.firstChild);
+ } else {
+ code.setAttribute('data-name', sourceUrl);
+ }
+ }
+ }
+ });
+});