Files
blog-eleventy-indiekit/search.njk
Ricardo 7cb0203adc fix: load pagefind once in base layout, eliminate duplicate scripts
Pagefind CSS/JS is now loaded once in base.njk <head> with defer.
A tiny initPagefind() helper queues widget inits until DOMContentLoaded
when PagefindUI is available. Removes duplicate <link>/<script> tags
from all sidebar widgets, search page, and 404 page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 10:50:32 +01:00

34 lines
1.0 KiB
Plaintext

---
layout: layouts/base.njk
title: Search
permalink: /search/
eleventyExcludeFromCollections: true
pagefindIgnore: true
---
<div class="page-header mb-6 sm:mb-8">
<h1 class="text-2xl sm:text-3xl font-bold text-surface-900 dark:text-surface-100 mb-2">Search</h1>
<p class="text-surface-600 dark:text-surface-400">Search across all posts, articles, notes, and pages.</p>
</div>
<div id="search"></div>
<script>
initPagefind("#search", { showSubResults: true });
// Support ?q= query parameter and auto-focus
window.addEventListener("DOMContentLoaded", () => {
const params = new URLSearchParams(window.location.search);
const query = params.get("q");
if (query) {
const input = document.querySelector("#search input[type='text']");
if (input) {
input.value = query;
input.dispatchEvent(new Event("input", { bubbles: true }));
}
} else {
const input = document.querySelector("#search input[type='text']");
if (input) input.focus();
}
});
</script>