From 42579e9ca81efd1f3cf8fd8586d72b05f4b182d2 Mon Sep 17 00:00:00 2001 From: Vidminas <5411598+Vidminas@users.noreply.github.com> Date: Thu, 9 Jul 2026 22:46:19 +0100 Subject: [PATCH 1/2] perf(search): load Pagefind lazily on first open; build index in dev Pagefind was imported eagerly in the search modal's init(), so its index loaded on every page view even when search was never opened. Move the import into an idempotent ensurePagefind() that runs when the modal first opens (and is awaited by search() to cover a user typing before that load finishes). Also build the Pagefind index in the academic-cv starter's `dev` script so search works under `pnpm dev` (mirrors the monorepo dev harness; output goes to the already-gitignored static/pagefind). Co-Authored-By: Claude Opus 4.8 --- .../_partials/components/search-modal.html | 42 ++++++++++++------- templates/academic-cv/package.json | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/modules/blox/layouts/_partials/components/search-modal.html b/modules/blox/layouts/_partials/components/search-modal.html index 03504ed99..5bca34c09 100644 --- a/modules/blox/layouts/_partials/components/search-modal.html +++ b/modules/blox/layouts/_partials/components/search-modal.html @@ -270,6 +270,7 @@

No results allFilters: [], trendingSearches: {{ site.Params.hugoblox.search.suggestions | default (slice "Search term 1" "Search term 2") | jsonify }}, pagefind: null, + pagefindLoading: false, pagefindModulePath: window.hbb?.assetPaths?.pagefind ?? '/pagefind/pagefind.js', // i18n translations for content types @@ -279,22 +280,13 @@

No results 'docs': {{ i18n "docs" | default "Documentation" | jsonify }} }, - async init() { - // Initialize Pagefind - try { - this.pagefind = await import(this.pagefindModulePath); - await this.pagefind.init(); - console.log('✓ Pagefind initialized'); - - // Load available filters - await this.loadFilters(); - } catch (error) { - console.error('Failed to initialize Pagefind:', error); - } - + init() { // Keyboard navigation this.$watch('$store.search.open', (open) => { if (open) { + // Load Pagefind lazily the first time the modal opens, so the search + // index isn't fetched on every page view. + this.ensurePagefind(); this.$nextTick(() => this.$refs.searchInput?.focus()); document.body.style.overflow = 'hidden'; } else { @@ -394,16 +386,36 @@

No results }); }, + // Load + initialise Pagefind once, on first use (first modal open, or a + // search if the user types before that load finishes). + async ensurePagefind() { + if (this.pagefind || this.pagefindLoading) return; + this.pagefindLoading = true; + try { + this.pagefind = await import(this.pagefindModulePath); + await this.pagefind.init(); + await this.loadFilters(); + } catch (error) { + console.error('Failed to initialize Pagefind:', error); + } finally { + this.pagefindLoading = false; + } + }, + async search() { if (!this.query.trim()) { this.results = []; this.hasSearched = false; return; } - + this.loading = true; this.hasSearched = false; // Reset until search completes - + + // Ensure the index is loaded (the user may type before the open-load finishes). + await this.ensurePagefind(); + if (!this.pagefind) { this.loading = false; return; } + try { const options = {}; diff --git a/templates/academic-cv/package.json b/templates/academic-cv/package.json index 4094bc305..13b498160 100644 --- a/templates/academic-cv/package.json +++ b/templates/academic-cv/package.json @@ -5,7 +5,7 @@ "packageManager": "pnpm@10.14.0", "description": "Academic CV starter template for Hugo Blox with Tailwind CSS v4", "scripts": { - "dev": "hugo server --disableFastRender", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", "build": "hugo --minify && pnpm run pagefind", "pagefind": "pagefind --site public" }, From d04d53a7e3777d48f2c9792396686107c9b01da4 Mon Sep 17 00:00:00 2001 From: Vidminas <5411598+Vidminas@users.noreply.github.com> Date: Sat, 11 Jul 2026 11:23:50 +0100 Subject: [PATCH 2/2] perf(search): build the Pagefind index in dev and build for all starters Extend the dev-time index build (previously only academic-cv) to every starter, and inline the Pagefind call in both `dev` and `build` instead of the `pnpm run pagefind` indirection: dev: hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server ... build: hugo --minify && pagefind --site public `dev` writes the index into static/ so `hugo server` serves it; `build` writes it straight into the deployed public/pagefind. The `pagefind` script is kept because each starter's netlify.toml still calls `pnpm run pagefind`. The `starter` base template keeps its `|| true` fault-guard, scoped in a subshell so it can't mask a Hugo failure. Co-Authored-By: Claude Opus 4.8 --- templates/academic-cv/package.json | 2 +- templates/data-science-blog/package.json | 4 ++-- templates/dev-portfolio/package.json | 4 ++-- templates/documentation/package.json | 4 ++-- templates/link-in-bio/package.json | 4 ++-- templates/markdown-slides/package.json | 4 ++-- templates/resume/package.json | 4 ++-- templates/saas-landing-page/package.json | 4 ++-- templates/starter/package.json | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/templates/academic-cv/package.json b/templates/academic-cv/package.json index 13b498160..4ea8a58be 100644 --- a/templates/academic-cv/package.json +++ b/templates/academic-cv/package.json @@ -6,7 +6,7 @@ "description": "Academic CV starter template for Hugo Blox with Tailwind CSS v4", "scripts": { "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/data-science-blog/package.json b/templates/data-science-blog/package.json index 5efd91c2d..241484cc8 100644 --- a/templates/data-science-blog/package.json +++ b/templates/data-science-blog/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Blog starter template for Hugo Blox with Tailwind CSS v4", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/dev-portfolio/package.json b/templates/dev-portfolio/package.json index a154de2c8..f4a6fb3a5 100644 --- a/templates/dev-portfolio/package.json +++ b/templates/dev-portfolio/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Modern developer portfolio template for Hugo Blox with Tailwind CSS v4 - Free version", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/documentation/package.json b/templates/documentation/package.json index 58dfec940..a3f3f01d4 100644 --- a/templates/documentation/package.json +++ b/templates/documentation/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Documentation starter template for Hugo Blox with Tailwind CSS v4", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/link-in-bio/package.json b/templates/link-in-bio/package.json index 895a3191e..a0646b7c3 100644 --- a/templates/link-in-bio/package.json +++ b/templates/link-in-bio/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Link-in-bio starter template for Hugo Blox with Tailwind CSS v4", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/markdown-slides/package.json b/templates/markdown-slides/package.json index 9ee844aa5..bb0b87247 100644 --- a/templates/markdown-slides/package.json +++ b/templates/markdown-slides/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Markdown Slides template - host and share slide decks built with Hugo Blox", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/resume/package.json b/templates/resume/package.json index 2607cf8ec..6fd983092 100644 --- a/templates/resume/package.json +++ b/templates/resume/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Resume starter template for Hugo Blox with Tailwind CSS v4", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/saas-landing-page/package.json b/templates/saas-landing-page/package.json index cac26ef85..eb87e532e 100644 --- a/templates/saas-landing-page/package.json +++ b/templates/saas-landing-page/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Landing page starter template for Hugo Blox with Tailwind CSS v4", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server --disableFastRender", + "build": "hugo --minify && pagefind --site public", "pagefind": "pagefind --site public" }, "dependencies": { diff --git a/templates/starter/package.json b/templates/starter/package.json index f76c18689..1e8c81e0b 100644 --- a/templates/starter/package.json +++ b/templates/starter/package.json @@ -5,8 +5,8 @@ "packageManager": "pnpm@10.14.0", "description": "Starter template for Hugo Blox with Tailwind CSS v4", "scripts": { - "dev": "hugo server --disableFastRender", - "build": "hugo --minify && pnpm run pagefind", + "dev": "hugo && (pagefind --site public --output-subdir ../static/pagefind 2>/dev/null || true) && hugo server --disableFastRender", + "build": "hugo --minify && (pagefind --site public 2>/dev/null || true)", "pagefind": "pagefind --site public 2>/dev/null || true" }, "dependencies": {