diff options
| author | Alejandro Soto <alejandro@34project.org> | 2025-09-13 14:55:15 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2025-09-13 14:55:15 -0600 |
| commit | 87f85704af1fa866be83077b2b351c1fdad7c3ce (patch) | |
| tree | b49c8d49ef717e539bff6578992e692eea55d380 /themes/tabi-lean/static/js/codeBlockNameLinks.js | |
| parent | 1a4c3216f027d6a6f36104547377b7b21faa5015 (diff) | |
| parent | a2ea06d513a5802964f8f0ef5795cec7e548ed7b (diff) | |
Merge commit 'a2ea06d513a5802964f8f0ef5795cec7e548ed7b' as 'themes/tabi-lean'
Diffstat (limited to 'themes/tabi-lean/static/js/codeBlockNameLinks.js')
| -rw-r--r-- | themes/tabi-lean/static/js/codeBlockNameLinks.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/themes/tabi-lean/static/js/codeBlockNameLinks.js b/themes/tabi-lean/static/js/codeBlockNameLinks.js new file mode 100644 index 0000000..ea0b678 --- /dev/null +++ b/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); + } + } + } + }); +}); |
