From 66360b9c7a3fd2d85764f2ef3cbe386b7b97010c Mon Sep 17 00:00:00 2001 From: lew Date: Fri, 27 Mar 2026 21:16:18 +0000 Subject: [PATCH] feat: adds find button to header --- www/public/js/params.js | 26 ++++++++++++++++++++++---- www/src/layouts/Layout.astro | 13 ++++++++++++- www/src/styles/global.css | 12 ------------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/www/public/js/params.js b/www/public/js/params.js index c466e18..01fbf1b 100644 --- a/www/public/js/params.js +++ b/www/public/js/params.js @@ -4,8 +4,7 @@ var just = p.get('just'); if (just && /^[a-z0-9-]+$/.test(just)) { document.documentElement.dataset.just = just; - var css = 'section[data-section]:not([data-section="' + just + '"]){display:none}' - + ' section[data-section="' + just + '"] .section-label{pointer-events:none;text-decoration:none;color:inherit}'; + var css = 'section[data-section]:not([data-section="' + just + '"]){display:none}'; document.head.appendChild(Object.assign(document.createElement('style'), { textContent: css })); } @@ -30,7 +29,10 @@ if (has) { document.documentElement.dataset.has = has; has = has.toLowerCase(); - document.addEventListener('DOMContentLoaded', function() { + } + + document.addEventListener('DOMContentLoaded', function() { + if (has) { document.querySelectorAll('section[data-section] .entry').forEach(function(entry) { if (entry.textContent.toLowerCase().indexOf(has) === -1) { entry.style.display = 'none'; @@ -41,6 +43,22 @@ entry.style.display = 'none'; } }); + } + + document.querySelectorAll('.section-label').forEach(function(a) { + var link = new URLSearchParams(a.search); + p.forEach(function(v, k) { if (!link.has(k)) link.set(k, v); }); + a.href = '?' + link.toString(); }); - } + + var find = document.getElementById('find'); + if (find) find.addEventListener('click', function(e) { + e.preventDefault(); + var term = prompt('find:'); + if (!term) return; + var q = new URLSearchParams(location.search); + q.set('has', term); + location.search = q.toString(); + }); + }); }(); diff --git a/www/src/layouts/Layout.astro b/www/src/layouts/Layout.astro index 5cea85d..ee442c2 100644 --- a/www/src/layouts/Layout.astro +++ b/www/src/layouts/Layout.astro @@ -28,7 +28,18 @@ const { title, description = 'personal website of ' + title, showHeader = true, {showHeader && (
- {isHome ? {title}{title} : lewis m.w.}mail gh rss sitemap random newest + + {isHome ? title : 'lewis m.w.'} + + + mail + gh + rss + sitemap + random + newest + find +
)} diff --git a/www/src/styles/global.css b/www/src/styles/global.css index 00a1bec..4e595c6 100644 --- a/www/src/styles/global.css +++ b/www/src/styles/global.css @@ -81,18 +81,6 @@ section { } -.home-name-link { - display: none; -} - -html[data-just] .home-name { - display: none; -} - -html[data-just] .home-name-link { - display: inline; -} - html[data-has] .guestbook-form { display: none; }