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>
This commit is contained in:
Ricardo
2026-02-13 10:50:32 +01:00
parent 60b59949ef
commit 7cb0203adc
6 changed files with 29 additions and 50 deletions

12
404.njk
View File

@@ -14,15 +14,5 @@ pagefindIgnore: true
</a>
</div>
<link rel="stylesheet" href="/pagefind/pagefind-ui.css">
<div id="search-404" class="max-w-2xl mx-auto"></div>
<script src="/pagefind/pagefind-ui.js"></script>
<script>
window.addEventListener("DOMContentLoaded", () => {
new PagefindUI({
element: "#search-404",
showSubResults: true,
showImages: false,
});
});
</script>
<script>initPagefind("#search-404", { showSubResults: true });</script>