From 7d93c9d88bfda89ea5a35293a4c4f42c55fa5268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20Barmore-Gen=C3=A7?= Date: Fri, 17 May 2024 23:02:18 -0500 Subject: [PATCH] Fix Pagefind not loading --- src/app.html | 2 -- src/routes/Header.svelte | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app.html b/src/app.html index 6052660..77a5ff5 100644 --- a/src/app.html +++ b/src/app.html @@ -8,7 +8,5 @@
%sveltekit.body%
- - diff --git a/src/routes/Header.svelte b/src/routes/Header.svelte index 26c7682..bc7ed2d 100644 --- a/src/routes/Header.svelte +++ b/src/routes/Header.svelte @@ -9,9 +9,21 @@ import List from 'phosphor-svelte/lib/List'; import { afterNavigate } from '$app/navigation'; - onMount(() => { + function loadPagefind() { // @ts-ignore new PagefindUI({ element: '#search', showSubResults: true }); + } + + onMount(() => { + try { + console.debug('Pagefind loaded, not waiting'); + loadPagefind(); + console.debug('Pagefind not loaded, waiting for DOMContentLoaded'); + } catch (e) { + window.addEventListener('DOMContentLoaded', () => { + loadPagefind(); + }); + } }); let expanded = false; @@ -21,6 +33,11 @@ }); + + + + +