fix: search not working when site deployed to sub-folder

This commit is contained in:
George Cushen committed 2025-11-15 16:18:46 +00:00
1 parent ad296b39a1
commit 89ab4d1a34
3 files changed
+15 -3

No files matched your search

@@ -3,10 +3,20 @@ import {applyHugoStyleFixes, initTheme} from "./hb-init.js";
// Initialize Hugo Blox Builder global object
const root = document.documentElement;
const defaultTheme = root.dataset.wcThemeDefault || "system";
const relBase = root.dataset.hbbRelurl || "/";
const normalizedRelBase = relBase.endsWith("/") ? relBase : `${relBase}/`;
const buildAssetPath = (relativePath) => {
const sanitizedRelative = relativePath.startsWith("/") ? relativePath.slice(1) : relativePath;
return `${normalizedRelBase}${sanitizedRelative}`;
};
// Create global HBB object with theme functions
window.hbb = {
defaultTheme: defaultTheme,
relBase: normalizedRelBase,
assetPaths: {
pagefind: buildAssetPath("pagefind/pagefind.js"),
},
setDarkTheme: () => {
root.classList.add("dark");
root.style.colorScheme = "dark";
@@ -269,6 +269,7 @@
availableFilters: [],
trendingSearches: {{ site.Params.features.search.trending_searches | default (slice "Search term 1" "Search term 2") | jsonify }},
pagefind: null,
pagefindModulePath: window.hbb?.assetPaths?.pagefind ?? '/pagefind/pagefind.js',
// i18n translations for content types
typeLabels: {
@@ -280,7 +281,7 @@
async init() {
// Initialize Pagefind
try {
this.pagefind = await import('/pagefind/pagefind.js');
this.pagefind = await import(this.pagefindModulePath);
await this.pagefind.init();
console.log('✓ Pagefind initialized');
@@ -520,4 +521,4 @@
<style>
[x-cloak] { display: none !important; }
</style>
</style>
+2 -1
View File
@@ -3,7 +3,8 @@
{{ printf "<!-- Last Published: %s -->" (now | time.Format ":date_long") | safeHTML }}
{{- $language_code := site.LanguageCode | default "en-us" -}}
<html lang="{{$language_code}}" {{ if in site.Data.i18n.rtl.rtl $language_code }}dir="rtl"{{else}}dir="ltr"{{end}}
data-wc-theme-default="{{ (lower site.Params.appearance.mode) | default "system" }}">
data-wc-theme-default="{{ (lower site.Params.appearance.mode) | default "system" }}"
data-hbb-relurl="{{ "" | relURL }}">
{{ partial "site_head" . }}
<body class="dark:bg-hb-dark dark:text-white page-wrapper" id="top">
<div id="page-bg"></div>