From c1abea085707147c2c23b4a5f66d6e69082bf8dd Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Wed, 11 Mar 2026 18:34:58 -0700 Subject: [PATCH] docs: give .pine files their own URL hash via docsify beforeEach hook Replace manual click-interception plugin with a clean beforeEach hook that detects .pine routes and wraps raw content in markdown code fences. This gives each .pine file its own unique URL (e.g. #/lib/.../atr.pine), supports direct linking, bookmarks, and browser back/forward navigation. --- index.html | 57 +++++++++++------------------------------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/index.html b/index.html index 79e7fa1f..c07df444 100644 --- a/index.html +++ b/index.html @@ -236,53 +236,18 @@ }, 100); }); }, - // Render .pine files as fixed-font code blocks inside docsify + // Render .pine files as syntax-highlighted code blocks with their own URL function(hook, vm) { - hook.doneEach(function() { - var content = document.querySelector('.markdown-section'); - if (!content) return; - content.querySelectorAll('a').forEach(function(a) { - var rawHref = a.getAttribute('href'); - if (!rawHref || !rawHref.endsWith('.pine')) return; - a.addEventListener('click', function(e) { - e.preventDefault(); - e.stopPropagation(); - // Extract the .pine path from the hash link or raw href - var pinePath = rawHref; - // If docsify converted it to a hash link: #/lib/.../file.pine - var fullHref = a.href || ''; - var hashIdx = fullHref.indexOf('#/'); - if (hashIdx !== -1) { - pinePath = fullHref.substring(hashIdx + 2); - } else if (!pinePath.startsWith('/') && !pinePath.startsWith('http')) { - // Relative link — resolve against current route's directory - var routeFile = (vm.route && vm.route.file) || ''; - var routeDir = routeFile.replace(/[^/]*$/, ''); - pinePath = routeDir + pinePath; - } - // Fetch from server root - var fetchUrl = pinePath.startsWith('/') ? pinePath : '/' + pinePath; - // For relative server (non-root), use document.baseURI - var absUrl = new URL(pinePath, document.baseURI).href; - fetch(absUrl).then(function(r) { - if (!r.ok) throw new Error(r.status + ' ' + r.statusText); - return r.text(); - }).then(function(text) { - // Verify we got pine content, not HTML fallback - if (text.trimStart().startsWith('Error

Could not load ' + pinePath + ': ' + err.message + '

'; - }); - }); - }); + hook.beforeEach(function(content, next) { + var routeFile = (vm.route && vm.route.file) || ''; + if (routeFile.endsWith('.pine')) { + var fname = routeFile.split('/').pop(); + // Wrap raw pine content in markdown code fence + var md = '# 📜 ' + fname + '\n\n```pine\n' + content + '\n```\n'; + next(md); + } else { + next(content); + } }); } ],