From 62ccab75220957cfb2e3824cdaf0aa132879400a Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 25 Aug 2026 14:20:47 -0400 Subject: [PATCH] try to improve search --- .github/workflows/deploy.yml | 3 +++ publish/quartz-patches/apply.py | 39 +++++++++++++++++++++++++++++++++ publish/setup.ps1 | 1 + 3 files changed, 43 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c27943a..6eb3b32 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -60,6 +60,9 @@ jobs: - name: Install theme package working-directory: site run: npm install @quartz-themes/everforest-spruce + - name: Patch search fuzz + working-directory: site + run: python ../publish/quartz-patches/apply.py search - name: Build Quartz working-directory: site run: npx quartz build -d .. diff --git a/publish/quartz-patches/apply.py b/publish/quartz-patches/apply.py index c23912d..5182f40 100644 --- a/publish/quartz-patches/apply.py +++ b/publish/quartz-patches/apply.py @@ -24,6 +24,16 @@ SCRIPT: Path = Path(__file__).resolve() VAULT: Path = SCRIPT.parents[2] QUARTZ_REPO: Path = VAULT / "site" / "quartz" SPA_FILE: Path = QUARTZ_REPO / "components" / "scripts" / "spa.inline.ts" +SEARCH_FILE: Path = ( + VAULT + / "site" + / "node_modules" + / "@quartz-community" + / "search" + / "dist" + / "components" + / "index.js" +) PUBLIC: Path = VAULT / "site" / "public" OVERLAY: Path = VAULT / "publish" / "quartz.config.yaml" @@ -128,6 +138,30 @@ def patch_spa() -> bool: return True +SEARCH_CONTENT_FORWARD: str = '{field:"content",tokenize:"forward"}' +SEARCH_CONTENT_FULL: str = '{field:"content",tokenize:"full"}' + + +def patch_search() -> bool: + """Index note bodies with FlexSearch `full` tokenize (substring match).""" + if not SEARCH_FILE.exists(): + print(f"missing {SEARCH_FILE}") + return False + text = SEARCH_FILE.read_text(encoding="utf-8") + if SEARCH_CONTENT_FULL in text: + print("search already patched") + return True + if SEARCH_CONTENT_FORWARD not in text: + print("search content tokenize missing") + return False + SEARCH_FILE.write_text( + text.replace(SEARCH_CONTENT_FORWARD, SEARCH_CONTENT_FULL, 1), + encoding="utf-8", + ) + print("search patched") + return True + + # --- post-build HTML rewrites ---------------------------------------------- @@ -199,6 +233,11 @@ def main() -> int: if not ok and mode == "spa": return 1 + if mode in ("search", "all"): + ok = patch_search() + if not ok and mode == "search": + return 1 + if mode in ("built", "all"): b, t, total = rewrite_built_htmls() print(f"base tag: {b}, title link: {t}, total {total}") diff --git a/publish/setup.ps1 b/publish/setup.ps1 index 78d185d..9b497df 100644 --- a/publish/setup.ps1 +++ b/publish/setup.ps1 @@ -12,3 +12,4 @@ Set-Location -LiteralPath $site npm ci npx quartz plugin install --from-config npm install @quartz-themes/everforest-spruce +python (Join-Path $PSScriptRoot "quartz-patches\apply.py") search