feat: adds find button to header
This commit is contained in:
parent
30212a2eaf
commit
66360b9c7a
3 changed files with 34 additions and 17 deletions
|
|
@ -4,8 +4,7 @@
|
||||||
var just = p.get('just');
|
var just = p.get('just');
|
||||||
if (just && /^[a-z0-9-]+$/.test(just)) {
|
if (just && /^[a-z0-9-]+$/.test(just)) {
|
||||||
document.documentElement.dataset.just = just;
|
document.documentElement.dataset.just = just;
|
||||||
var css = 'section[data-section]:not([data-section="' + just + '"]){display:none}'
|
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}';
|
|
||||||
document.head.appendChild(Object.assign(document.createElement('style'), { textContent: css }));
|
document.head.appendChild(Object.assign(document.createElement('style'), { textContent: css }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +29,10 @@
|
||||||
if (has) {
|
if (has) {
|
||||||
document.documentElement.dataset.has = has;
|
document.documentElement.dataset.has = has;
|
||||||
has = has.toLowerCase();
|
has = has.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
if (has) {
|
||||||
document.querySelectorAll('section[data-section] .entry').forEach(function(entry) {
|
document.querySelectorAll('section[data-section] .entry').forEach(function(entry) {
|
||||||
if (entry.textContent.toLowerCase().indexOf(has) === -1) {
|
if (entry.textContent.toLowerCase().indexOf(has) === -1) {
|
||||||
entry.style.display = 'none';
|
entry.style.display = 'none';
|
||||||
|
|
@ -41,6 +43,22 @@
|
||||||
entry.style.display = 'none';
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
}();
|
}();
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,18 @@ const { title, description = 'personal website of ' + title, showHeader = true,
|
||||||
<body>
|
<body>
|
||||||
{showHeader && (
|
{showHeader && (
|
||||||
<header>
|
<header>
|
||||||
<span class="header-name">{isHome ? <Fragment><span class="home-name">{title}</span><a class="home-name-link" href="/">{title}</a></Fragment> : <a href="/">lewis m.w.</a>}</span><span class="header-links"><a href="mailto:lewis@wynne.rs">mail</a> <a href="https://github.com/llywelwyn">gh</a> <a href="/feed.xml">rss</a> <a href="/sitemap.txt">sitemap</a> <a href="/?do=random">random</a> <a href="/?do=newest">newest</a></span>
|
<span class="header-name">
|
||||||
|
<a href="/">{isHome ? title : 'lewis m.w.'}</a>
|
||||||
|
</span>
|
||||||
|
<span class="header-links">
|
||||||
|
<a href="mailto:lewis@wynne.rs">mail</a>
|
||||||
|
<a href="https://github.com/llywelwyn">gh</a>
|
||||||
|
<a href="/feed.xml">rss</a>
|
||||||
|
<a href="/sitemap.txt">sitemap</a>
|
||||||
|
<a href="/?do=random">random</a>
|
||||||
|
<a href="/?do=newest">newest</a>
|
||||||
|
<a id="find" href="/?has=">find</a>
|
||||||
|
</span>
|
||||||
</header>
|
</header>
|
||||||
)}
|
)}
|
||||||
<slot />
|
<slot />
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
html[data-has] .guestbook-form {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue