From b7a66310d75efa003bde829f346552deb1772db4 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Wed, 10 Dec 2025 01:36:37 +0000 Subject: [PATCH] feat: disable debug HUD by default Enable with site.Params.hugoblox.debug.enable = true --- .../hooks/body-end/hbx-debug-export.html | 2 +- .../hooks/body-end/hbx-debug-hud.html | 802 +++++++++--------- modules/blox-tailwind/layouts/baseof.html | 6 +- 3 files changed, 405 insertions(+), 405 deletions(-) diff --git a/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-export.html b/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-export.html index dae0cecb..d6c3bb68 100644 --- a/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-export.html +++ b/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-export.html @@ -1,5 +1,5 @@ {{/* Hugo Blox: Export Debug Logs for Dev HUD (window var) */}} -{{- if and hugo.IsServer (site.Params.hugoblox.debug.export_logs | default true) -}} +{{- if site.Params.hugoblox.debug.export_logs | default true -}} {{- /* Collect all logs from all pages (site-wide) */ -}} {{- $entries := slice -}} {{- range .Site.Pages -}} diff --git a/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-hud.html b/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-hud.html index 35ef0363..aa53ae91 100644 --- a/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-hud.html +++ b/modules/blox-tailwind/layouts/_partials/hooks/body-end/hbx-debug-hud.html @@ -1,412 +1,410 @@ {{/* Hugo Blox: Dev HUD (floating button + panel). Dev only. */}} -{{- if hugo.IsServer -}} - -{{- end -}} + // Update logs + const visible = logs.filter(e => e.level==='error' || e.level==='warn' || (e.level==='info' && shouldShowInfo())); + const errs = visible.filter(e => e.level==='error').length; + const warns = visible.filter(e => e.level==='warn').length; + const total = errs + warns + (shouldShowInfo()? visible.filter(e=>e.level==='info').length : 0); + badge.textContent = String(total); + badge.hidden = total === 0; + + // Update tab badge + logsTab.textContent = `Logs${total > 0 ? ` (${total})` : ''}`; + + logsContent.replaceChildren(); + const groupByPage = new Map(); + for (const e of visible) { + const key = e.page || '/'; + if (!groupByPage.has(key)) groupByPage.set(key, []); + groupByPage.get(key).push(e); + } + for (const [page, entries] of groupByPage) { + const h = document.createElement('div'); + h.className = 'page-group-header'; + h.textContent = page; + logsContent.appendChild(h); + for (const e of entries.sort((a,b)=> (a.level>b.level?-1:1) || (a.timestamp-b.timestamp))) { + const row = document.createElement('div'); + row.className = `entry ${e.level}`; + const lvl = document.createElement('div'); + lvl.className='lvl'; + lvl.textContent=e.level; + const msg = document.createElement('div'); + msg.className='msg'; + msg.textContent = e.message || ''; + const metaEl = document.createElement('div'); + metaEl.className='meta'; + metaEl.textContent = new Date(e.timestamp*1000).toLocaleTimeString(); + row.append(lvl, msg, metaEl); + logsContent.appendChild(row); + } + } + }; + + const refreshFromWindow = () => { + if (window.__HBX_LOGS__) { + setLogs(window.__HBX_LOGS__); + } + }; + const fetchLogs = async () => { + try { + const res = await fetch('/hbx-debug.json?cb=' + Date.now()); + if (res.ok) { const data = await res.json(); setLogs(data); render(); } + } catch (e) { /* silent */ } + }; + + const openPanel = () => { + panel.classList.add('open'); + refreshFromWindow(); + render(); + fetchLogs(); + }; + const closePanel = () => { + panel.classList.remove('open'); + }; + const togglePanel = () => { + if (panel.classList.contains('open')) { + closePanel(); + } else { + openPanel(); + } + }; + + btn.addEventListener('click', togglePanel); + close.addEventListener('click', closePanel); + chkInfo.addEventListener('change', () => { + localStorage.setItem('hbx-show-info', chkInfo.checked ? '1' : ''); + render(); + }); + chkAuto.addEventListener('change', () => { + localStorage.setItem('hbx-auto-open', chkAuto.checked ? '1' : ''); + }); + chkHide.addEventListener('change', () => { + const hideButton = chkHide.checked; + setButtonVisibility(hideButton); + if (hideButton) { + openPanel(); + } + }); + placementSelect.addEventListener('change', () => { + setPlacement(placementSelect.value); + }); + + // Initial render immediately on load + refreshFromWindow(); + render(); // Force initial render even without data + + // Auto-open panel if user enabled it + if (chkAuto.checked) { + openPanel(); + } + + const handleShortcut = (event) => { + const key = (event.key || '').toLowerCase(); + if (key === 'd' && event.shiftKey && (event.metaKey || event.ctrlKey)) { + event.preventDefault(); + togglePanel(); + } + }; + window.addEventListener('keydown', handleShortcut); + + // Auto-refresh badge every few seconds in dev + setInterval(() => { refreshFromWindow(); }, 3000); + } catch(e) { /* ignore */ } +})(); + diff --git a/modules/blox-tailwind/layouts/baseof.html b/modules/blox-tailwind/layouts/baseof.html index 0351d246..66490c3b 100644 --- a/modules/blox-tailwind/layouts/baseof.html +++ b/modules/blox-tailwind/layouts/baseof.html @@ -37,7 +37,9 @@ {{ partial "functions/get_hook" (dict "hook" "body-end" "context" .) }} {{/* HBX Dev: ensure debug export and HUD are injected in dev */}} - {{ partial "hooks/body-end/hbx-debug-export.html" . }} - {{ partial "hooks/body-end/hbx-debug-hud.html" . }} + {{ if hugo.IsServer | and (site.Params.hugoblox.debug.enable | default false) }} + {{ partial "hooks/body-end/hbx-debug-export.html" . }} + {{ partial "hooks/body-end/hbx-debug-hud.html" . }} + {{ end }}