feat: Add client-side search, reading time estimates, and a reading progress bar, plus a clipboard copy fallback.

This commit is contained in:
2026-03-11 22:07:01 +03:00
parent 18cc61af31
commit 6c8776a4cc
12 changed files with 457 additions and 98 deletions
-13
View File
@@ -6,11 +6,8 @@ Feature backlog for the blog. Check off items as they're implemented.
## Discovery & Navigation
- [ ] **Client-side search** — enable `build_search_index = true` in `zola.toml`, add a search page/modal with Elasticlunr
- [ ] **Reading time estimate** — use `page.reading_time` to display "X min read" in post headers
- [ ] **Related posts** — show 2–3 posts with overlapping tags at the bottom of each post
- [ ] **Post series support** — `series` front-matter field; render a "Part N of X" callout with links to all parts in the series
- [ ] **Keyboard shortcuts** — `K` to open search, `T` to toggle theme; show a small hotkey hint overlay
---
@@ -18,25 +15,15 @@ Feature backlog for the blog. Check off items as they're implemented.
- [ ] **Callout / admonition shortcodes** — `{% note %}`, `{% warning %}`, `{% tip %}`, `{% danger %}` Tera shortcodes styled as terminal callout boxes
- [x] **Updated-at badge** — show "Last updated: <date>" on posts that have `updated` front-matter set, distinct from the published date
---
## Post List & Filtering
- [ ] **Tag filtering on posts page** — JS-powered tag chip filter; clicking a tag hides non-matching posts without a page reload
- [ ] **Reading progress bar** — thin accent-colored bar at the top of the viewport that fills as you scroll through a post
- [ ] **Post view count** — Cloudflare Worker + KV store to track and display view counts (fits existing `wrangler.toml` setup)
- [ ] **Sort / filter controls on posts page** — toggle between newest-first, oldest-first, and filter by tag or difficulty
---
## UI / UX Polish
- [ ] **Smooth page transitions** — CSS View Transitions API for navigation between pages
- [ ] **Footnote hover previews** — hover over a footnote ref to see its content in a tooltip without jumping to the bottom
---
## Distribution & Reach
+21
View File
@@ -1,3 +1,24 @@
// Article details and content styling
.reading-progress-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 3px;
background-color: transparent;
z-index: 1000;
pointer-events: none;
}
.reading-progress-bar {
height: 100%;
width: 0%;
background-color: var(--accent-color);
box-shadow: 0 0 10px rgba(16, 185, 129, 0.5); /* Glowing emerald accent */
transition: width 0.1s cubic-bezier(0.25, 0.8, 0.25, 1);
}
// Post Detail
.post-detail {
max-width: 800px;
+100 -75
View File
@@ -1,50 +1,68 @@
// Search overlay
// Search Modal Styles
.search-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.8);
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.4);
backdrop-filter: blur(4px);
z-index: 9999;
display: none;
align-items: flex-start;
-webkit-backdrop-filter: blur(4px);
z-index: 10000;
display: flex;
justify-content: center;
padding: 2rem;
overflow-y: auto;
align-items: flex-start;
padding-top: 10vh;
opacity: 0;
visibility: hidden;
transition:
opacity 0.2s ease,
visibility 0.2s ease;
&.is-active {
display: flex;
&.active {
opacity: 1;
visibility: visible;
.search-modal {
transform: translateY(0) scale(1);
}
}
}
.search-modal {
background-color: var(--bg-color);
width: 90%;
max-width: 600px;
background: var(--bg-color);
border: 1px solid var(--border-color);
border-radius: 0.5rem;
max-width: 42rem;
width: 100%;
margin-top: 10vh;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
border-radius: 12px;
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
transform: translateY(-20px) scale(0.98);
transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
display: flex;
flex-direction: column;
overflow: hidden;
}
.search-header {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 1rem;
padding: 1rem 1.25rem;
border-bottom: 1px solid var(--border-color);
background: var(--surface-color);
svg {
color: var(--text-muted);
margin-right: 0.75rem;
}
}
.search-input {
#search-input {
flex: 1;
font-size: 1.125rem;
padding: 0.5rem;
background: transparent;
border: none;
color: var(--text-color);
font-family: var(--font-sans);
font-size: 1.1rem;
outline: none;
&::placeholder {
@@ -52,75 +70,82 @@
}
}
.search-close {
background: transparent;
border: none;
color: var(--text-muted);
cursor: pointer;
padding: 0.25rem;
.search-footer {
padding: 0.5rem 1.25rem;
background: var(--surface-color);
border-top: 1px solid var(--border-color);
display: flex;
justify-content: space-between;
align-items: center;
justify-content: center;
border-radius: 0.25rem;
transition: background-color 0.2s ease;
font-size: 0.75rem;
color: var(--text-muted);
&:hover {
background-color: var(--border-color);
color: var(--text-color);
kbd {
background: var(--bg-color);
border: 1px solid var(--border-color);
border-radius: 4px;
padding: 0.1rem 0.3rem;
font-family: var(--font-mono);
font-size: 0.7rem;
margin: 0 0.2rem;
}
}
.search-results {
max-height: 60vh;
max-height: 50vh;
overflow-y: auto;
padding: 0.5rem;
}
.search-result-item {
display: block;
padding: 1rem;
border-radius: 0.375rem;
text-decoration: none;
color: var(--text-color);
transition: background-color 0.2s ease;
&:hover {
// Custom scrollbar
&::-webkit-scrollbar {
width: 8px;
}
&::-webkit-scrollbar-track {
background: transparent;
}
&::-webkit-scrollbar-thumb {
background-color: var(--border-color);
border-radius: 4px;
}
}
.search-result-title {
font-size: 1rem;
font-weight: 600;
margin: 0 0 0.5rem 0;
color: var(--accent-color);
}
.search-result-item {
display: flex;
flex-direction: column;
padding: 0.75rem 1rem;
border-radius: 8px;
text-decoration: none;
color: var(--text-color);
transition: background-color 0.15s ease;
border-left: 2px solid transparent;
.search-result-snippet {
font-size: 0.875rem;
color: var(--text-muted);
margin: 0;
line-height: 1.5;
}
&:hover,
&.selected {
background-color: var(--surface-color);
border-left-color: var(--accent-color);
}
.search-no-results {
padding: 2rem;
text-align: center;
color: var(--text-muted);
}
.result-title {
font-weight: 500;
color: var(--accent-color);
margin-bottom: 0.25rem;
}
.search-footer {
padding: 0.75rem 1rem;
border-top: 1px solid var(--border-color);
font-size: 0.75rem;
color: var(--text-muted);
text-align: center;
.result-summary {
font-size: 0.85rem;
color: var(--text-muted);
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
}
kbd {
padding: 0.125rem 0.375rem;
background-color: var(--border-color);
border-radius: 0.25rem;
font-family: var(--font-mono);
font-size: 0.75rem;
.no-results {
padding: 2rem;
text-align: center;
color: var(--text-muted);
font-style: italic;
}
}
+18 -2
View File
@@ -28,8 +28,24 @@ document.addEventListener('DOMContentLoaded', () => {
const text = code.innerText;
try {
// Wait for the clipboard API
await navigator.clipboard.writeText(text);
if (navigator.clipboard && window.isSecureContext) {
// Modern Async Clipboard API
await navigator.clipboard.writeText(text);
} else {
// Fallback for insecure contexts (like local network IPs via HTTP)
const textArea = document.createElement('textarea');
textArea.value = text;
// Move outside the screen to make it invisible
textArea.style.position = 'absolute';
textArea.style.left = '-999999px';
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
textArea.remove();
}
// Add visual feedback
button.innerHTML = checkIcon;
+10
View File
File diff suppressed because one or more lines are too long
+34
View File
@@ -0,0 +1,34 @@
document.addEventListener('DOMContentLoaded', () => {
const progressBar = document.getElementById('reading-progress-bar');
if (!progressBar) return;
const updateProgress = () => {
// Calculate how far the user has scrolled down the page
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
// Calculate the total scrollable height
const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
const clientHeight = document.documentElement.clientHeight || window.innerHeight;
const windowHeight = scrollHeight - clientHeight;
// Calculate percentage and update width
const scrollPercentage = windowHeight > 0 ? (scrollTop / windowHeight) * 100 : 0;
progressBar.style.width = scrollPercentage + '%';
};
// Update initially in case the user refreshes midway down the page
updateProgress();
// Throttle the scroll event listener a tiny bit for performance
let isTicking = false;
window.addEventListener('scroll', () => {
if (!isTicking) {
window.requestAnimationFrame(() => {
updateProgress();
isTicking = false;
});
isTicking = true;
}
});
});
+223
View File
@@ -0,0 +1,223 @@
document.addEventListener('DOMContentLoaded', () => {
const searchToggleBtn = document.querySelector('.search-toggle');
if (!searchToggleBtn) return;
// Check if elasticlunr is available
if (typeof elasticlunr === 'undefined') {
console.warn('Elasticlunr not loaded. Search will not work.');
return;
}
// Modal elements
const overlay = document.getElementById('search-overlay');
const input = document.getElementById('search-input');
const resultsContainer = document.getElementById('search-results');
if (!overlay || !input || !resultsContainer) return;
let index = null;
let isIndexLoading = false;
let selectedIndex = -1;
let resultItems = [];
// Initialize search index (loaded lazily on first open)
const initSearch = async () => {
if (index || isIndexLoading) return;
isIndexLoading = true;
try {
// Fetch the Zola-generated index
const response = await fetch('/search_index.en.js');
const jsText = await response.text();
// The file defines `window.searchIndex = {...}`
// We use a safe evaluation approach if it's purely assignment
// Or just append it as a script tag
const script = document.createElement('script');
script.innerHTML = jsText;
document.body.appendChild(script);
// Wait for it to parse
setTimeout(() => {
if (window.searchIndex) {
index = elasticlunr.Index.load(window.searchIndex);
// Search immediately if there's text
if (input.value.trim().length > 0) {
performSearch();
}
}
}, 50);
} catch (e) {
console.error('Failed to load search index:', e);
}
};
// Open Modal
const openSearch = () => {
overlay.classList.add('active');
// Slight delay ensures the browser focuses the input after the display transition starts
setTimeout(() => {
input.focus();
}, 50);
initSearch();
document.body.style.overflow = 'hidden'; // Prevent background scrolling
};
// Close Modal
const closeSearch = () => {
overlay.classList.remove('active');
input.value = '';
resultsContainer.innerHTML = '';
document.body.style.overflow = '';
selectedIndex = -1;
resultItems = [];
};
// Bind Toggle Button
searchToggleBtn.addEventListener('click', (e) => {
e.preventDefault();
if (overlay.classList.contains('active')) {
closeSearch();
} else {
openSearch();
}
});
// Close on overlay click
overlay.addEventListener('click', (e) => {
if (e.target === overlay) closeSearch();
});
// Handle Keyboard Shortcuts
document.addEventListener('keydown', (e) => {
// Ctrl+K -> Open Search
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
openSearch();
}
if (!overlay.classList.contains('active')) return;
// Escape -> Close Search
if (e.key === 'Escape') {
closeSearch();
}
// Arrow Navigation
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
e.preventDefault();
if (resultItems.length === 0) return;
if (e.key === 'ArrowDown') {
selectedIndex = (selectedIndex + 1) % resultItems.length;
} else {
selectedIndex = (selectedIndex - 1 + resultItems.length) % resultItems.length;
}
updateSelection();
}
// Enter -> Navigate to selected
if (e.key === 'Enter') {
e.preventDefault();
if (selectedIndex >= 0 && resultItems[selectedIndex]) {
window.location.href = resultItems[selectedIndex].href;
} else if (resultItems.length > 0) {
// Default to first item if none selected
window.location.href = resultItems[0].href;
}
}
});
const updateSelection = () => {
resultItems.forEach((el, i) => {
if (i === selectedIndex) {
el.classList.add('selected');
el.scrollIntoView({ block: 'nearest' });
} else {
el.classList.remove('selected');
}
});
};
// Perform the Search
const performSearch = () => {
if (!index) {
resultsContainer.innerHTML = '<div class="no-results">Loading search index...</div>';
return;
}
const query = input.value.trim();
if (query.length === 0) {
resultsContainer.innerHTML = '';
selectedIndex = -1;
resultItems = [];
return;
}
const options = {
bool: 'OR',
expand: true,
};
const results = index.search(query, options);
if (results.length === 0) {
resultsContainer.innerHTML = `<div class="no-results">No results found for "${query}"</div>`;
selectedIndex = -1;
resultItems = [];
return;
}
// Build HTML
let html = '';
results.forEach((res) => {
// The doc is stored inside the index.documentStore
// For Zola + elasticlunr, res.ref IS the URL.
const url = res.ref;
const doc = index.documentStore.docs[res.ref];
if (!doc) return;
// Truncate summary if needed
let body = doc.body || '';
if (body.length > 150) {
body = body.substring(0, 150) + '...';
}
const title = doc.title || url;
html += `
<a href="${url}" class="search-result-item">
<div class="result-title">${title}</div>
<div class="result-summary">${body}</div>
</a>
`;
});
resultsContainer.innerHTML = html;
// Cache DOM elements for keyboard navigation
resultItems = Array.from(resultsContainer.querySelectorAll('.search-result-item'));
selectedIndex = -1; // Reset selection on new search
// Mouse hover updates selection index
resultItems.forEach((item, i) => {
item.addEventListener('mouseenter', () => {
selectedIndex = i;
updateSelection();
});
});
};
// Debounce the input
let debounceTimer;
input.addEventListener('input', () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
performSearch();
}, 150);
});
});
+23 -3
View File
@@ -250,10 +250,30 @@
<polyline points="18 15 12 9 6 15"></polyline>
</svg>
</button>
<script src="{{ get_url(path="js/theme.js") }}"></script>
<script src="{{ get_url(path="js/copy-code.js") }}"></script>
<!-- Search Modal Overlay -->
<div id="search-overlay" class="search-overlay" aria-hidden="true">
<div class="search-modal" role="dialog" aria-modal="true" aria-label="Search posts">
<div class="search-header">
<svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
<input type="text" id="search-input" placeholder="Search posts..." autocomplete="off">
</div>
<div id="search-results" class="search-results"></div>
<div class="search-footer">
<span>Navigate: <kbd>↑</kbd> <kbd>↓</kbd></span>
<span>Select: <kbd>Enter</kbd></span>
<span>Close: <kbd>ESC</kbd></span>
</div>
</div>
</div>
<!-- Global Scripts -->
<script defer src="{{ get_url(path="js/theme.js") }}"></script>
<script defer src="{{ get_url(path="js/scroll-top.js") }}"></script>
<script defer src="{{ get_url(path="js/copy-code.js") }}"></script>
<!-- Search Scripts -->
<script defer src="{{ get_url(path="js/elasticlunr.min.js") }}"></script>
<script defer src="{{ get_url(path="js/search.js") }}"></script>
{% block scripts %}{% endblock scripts %}
</body>
</html>
+13
View File
@@ -79,10 +79,17 @@
</script>
{% endif %}
<!-- Reading Progress Bar -->
<script defer src="{{ get_url(path="js/progress.js") }}"></script>
{% endblock head %}
{% block content %}
<div class="reading-progress-container" aria-hidden="true">
<div class="reading-progress-bar" id="reading-progress-bar"></div>
</div>
<article class="post-detail">
<header class="post-header">
<h1 class="post-title">{{ page.title }}</h1>
@@ -100,6 +107,12 @@
<time datetime="{{ page.updated }}">{{ page.updated | date(format="%B %e, %Y") }}</time>
</span>
{% endif %}
{% if page.reading_time %}
<span class="post-meta-sep" aria-hidden="true">·</span>
<span class="post-meta-item">
{{ page.reading_time }} min read
</span>
{% endif %}
</div>
</header>
+4
View File
@@ -18,6 +18,10 @@
"
>
<span>{{ page.date | date(format="%Y-%m-%d") }}</span>
{% if page.reading_time %}
<span style="opacity: 0.5;">&middot;</span>
<span>{{ page.reading_time }} min read</span>
{% endif %}
</div>
<div
+9 -3
View File
@@ -55,9 +55,15 @@ block content %}
{% for page in paginator.pages %}
<article class="feed-item hover-scale">
<a href="{{ page.permalink }}" class="item-link">
<time datetime="{{ page.date }}" class="item-date"
>{{ page.date | date(format="%b %d, %Y") }}</time
>
<div style="display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem;">
<time datetime="{{ page.date }}" class="item-date"
>{{ page.date | date(format="%b %d, %Y") }}</time
>
{% if page.reading_time %}
<span style="color: var(--text-muted); font-size: 0.85rem; opacity: 0.6;">&middot;</span>
<span style="color: var(--text-muted); font-size: 0.85rem; font-family: var(--font-mono);">&sim;{{ page.reading_time }} min read</span>
{% endif %}
</div>
<h2 class="item-title">{{ page.title }}</h2>
{% if page.description %}
<p class="item-desc">{{ page.description }}</p>
+2 -2
View File
@@ -2,7 +2,7 @@ base_url = "https://pwnforfunandprofit.xyz"
title = "Pwn For Fun And Profit"
description = "Hacking the Narrative, One Byte at a Time."
compile_sass = true
build_search_index = false
build_search_index = true
taxonomies = [{ name = "tags" }]
generate_feeds = true
feed_filenames = ["rss.xml", "feed.json"]
@@ -54,6 +54,6 @@ name = "Archive"
url = "@/archive/_index.md"
# Features
enable_search = false
enable_search = true
enable_theme_toggle = true
show_rss_link = true