feat(header): add resume button and SVG icon
This commit is contained in:
1 parent
480259a4eb
commit
9ddbad4674
5 files changed
+32
-149
No files matched your search
@@ -1,147 +0,0 @@
|
||||
# Task Handoff — Search Function Fix (Astro / Spaghet.io)
|
||||
|
||||
## TL;DR
|
||||
|
||||
The `/search` page had **two** root causes, both now fixed and verified in the
|
||||
working tree. `astro check` → 0 errors, `npm test` → 11/11 pass,
|
||||
`astro build` → exit 0. Remaining work is **browser confirmation** and a
|
||||
**separate production-deploy problem** (see "Not done").
|
||||
|
||||
Complexity: **Standard** track. Repo: brownfield Astro 7.3.8 + Solid 1.9.17,
|
||||
`output: "server"` with `@astrojs/node` SSR adapter.
|
||||
|
||||
## Root causes found
|
||||
|
||||
1. **`?search=` URL param was never read.** `src/pages/search/index.astro`
|
||||
used `new URL(typeof window !== 'undefined' ? window.location.href :
|
||||
'http://localhost')`. Astro frontmatter runs on the **server**, so `window`
|
||||
is always undefined → it always fell back to a query-less localhost URL.
|
||||
Refresh, share, and back/forward silently produced an empty search.
|
||||
Fixed to `Astro.url.searchParams.get("search") ?? ""`.
|
||||
|
||||
2. **Zero-match queries rendered nothing at all.** The result block was gated
|
||||
on `query().length >= 2 && (posts.length > 0 || projects.length > 0)`, so a
|
||||
search with no hits showed a blank page — indistinguishable from a crash.
|
||||
Added explicit "No results for '…'" and "Keep typing…" states.
|
||||
|
||||
3. (Bonus, real) **Full markdown `body` was serialized into the island's
|
||||
`props`** — 21,873 chars / 43,572-byte page — while the filter only matched
|
||||
title/summary/tags. Removed.
|
||||
|
||||
## ⚠️ The trap that caused a 500 (read this before touching Search.tsx)
|
||||
|
||||
`output: "server"` + `client:load` means the **Solid component body executes on
|
||||
the server**, and Solid also runs `onCleanup` during **server teardown**. So:
|
||||
|
||||
- Top-level `window.addEventListener(...)` in the body → `ReferenceError:
|
||||
window is not defined` → 500.
|
||||
- `window.removeEventListener(...)` inside `onCleanup` → **also** throws on the
|
||||
server. This was my own regression and is why `/search` briefly 500'd.
|
||||
|
||||
Rules now encoded in the file:
|
||||
- Browser API access lives in `onMount` (never runs on server), **or** is
|
||||
gated by the `popStateBound` flag inside `onCleanup`.
|
||||
- `syncUrl()` has a `typeof window === "undefined"` guard.
|
||||
- Also: JSX text is assigned via `textContent`, so HTML entities like
|
||||
`—` render literally. Use real `—` characters in JSX text.
|
||||
|
||||
|
||||
## Files changed / added
|
||||
|
||||
| File | Change |
|
||||
|---|---|
|
||||
| `src/lib/search.ts` **(new)** | Fuse.js 7.1.0 wrapper: `createSearcher`, `runSearch`, `partitionByCollection`, `MIN_QUERY_LENGTH = 2`, weighted keys title .4 / tags .35 / summary .25, `threshold: 0.4`, `ignoreLocation: true` |
|
||||
| `src/lib/content.ts` **(new)** | `toSearchEntry(entry)` — single mapper shared by every page that renders cards |
|
||||
| `src/lib/types.ts` | Added `SearchEntry` + `CardEntry` union (source of truth for the type) |
|
||||
| `src/pages/search/index.astro` | `Astro.url.searchParams` fix; emits slim `entries` prop |
|
||||
| `src/components/Search.tsx` | Uses searcher; `searched` state flag; empty/short-query states; `syncUrl` (replaceState on debounce, pushState on submit); `onPopState` restore; `onMount` + `popStateBound`; `ReturnType<typeof setTimeout>` instead of `NodeJS.Timeout` |
|
||||
| `src/components/ArrowCard.tsx` | Dropped `any` → `CardEntry`; resolves `collection` from entry **or** prop; `slug` fallback |
|
||||
| `src/pages/index.astro` | Uses `toSearchEntry` (was emitting legacy `$id` + `Date`) |
|
||||
| `src/lib/__tests__/search.test.ts` **(new)** | 11 unit tests |
|
||||
| `vitest.config.ts` **(new)** | node env + `@lib`-style aliases mirroring tsconfig |
|
||||
| `package.json` | Added `"test": "vitest run"`, `"test:watch": "vitest"` |
|
||||
| `.clinerules/tool-catalog.md` **(new)** | Records the only real tools here (`editor`, `read_files`, `run_commands`, `search_codebase`, `ask_question`, `skills`, `fetch_web_content`, `searxng-*`). `.clinerules` is gitignored, so this is local-only. |
|
||||
|
||||
## Verified evidence
|
||||
|
||||
```
|
||||
search?search=astro -> query prop [0,"astro"] ssr input value="astro" (was [0,""] / "")
|
||||
island props -> 3,576 chars (was 21,873)
|
||||
/search page -> 25,304 bytes (was 43,572)
|
||||
/search / /blog -> HTTP 200, no ReferenceError in server log
|
||||
homepage card hrefs -> /blog/01-…, /projects/astro-profile (no 404 regression)
|
||||
astro check -> 0 errors, 0 warnings
|
||||
npm test -> 11 passed
|
||||
astro build -> exit 0
|
||||
bundle Search.DxvATC7F.js contains "No results for", "Keep typing",
|
||||
pushState, replaceState, popstate, Fuse 7.1.0
|
||||
```
|
||||
|
||||
## How to reproduce the verification
|
||||
|
||||
```bash
|
||||
cd "/home/spaghet/Documents/Spaghet.io"
|
||||
npx astro build
|
||||
node -e "import('./dist/server/entry.mjs').then(m=>m.startServer())" &
|
||||
# fetch /search?search=astro, then parse the <astro-island props="..."> attribute
|
||||
# (decode " -> " and JSON.parse; keys should be [query, entries])
|
||||
```
|
||||
|
||||
|
||||
## NOT done — remaining work
|
||||
|
||||
1. **Browser-level confirmation (do this first).** No `jsdom`/`happy-dom`/
|
||||
`playwright` is installed, so hydration and typing behaviour were verified
|
||||
only indirectly (SSR markup, decoded props, module resolution, bundle
|
||||
greps) — **not** by executing client JS. Load `/search`, type `astro`,
|
||||
confirm results render, confirm the URL gains `?search=astro`, press
|
||||
back/forward, and search `zzzq` to see "No results for 'zzzq'".
|
||||
|
||||
2. **Production is a different, stale build — SEPARATE ISSUE.**
|
||||
`spaghet.io/search` → 307 → `home.spaghet.io/search/`, which serves
|
||||
`Search.JqbiLQV3.js` (Fuse-based, single `data` prop, **8** docs — including
|
||||
`02-appwrite-nginx-reverse-proxy-fix` and an `appwrite` project that no
|
||||
longer exist in this repo). The local build emits `Search.DxvATC7F.js` with
|
||||
an `entries` prop. Deploying `main` changes live behaviour; review the diff
|
||||
first. No Dockerfile/CI in-repo — deploy is Gitea → GitHub → self-hosted →
|
||||
NGINX (see README).
|
||||
|
||||
3. **Unrelated pre-existing dirt in the tree.** `src/styles/global.css`,
|
||||
`tailwind.config.mjs`, `public/js/theme.js` and `astro.config.mjs` already
|
||||
carried an uncommitted Tailwind v3→v4 migration before this task.
|
||||
`tailwind.config.mjs` is orphaned under v4 unless `@config` is used.
|
||||
**Do not bundle that into the search commit** without asking.
|
||||
|
||||
4. **Body-content search was deliberately dropped** with the payload trim.
|
||||
If wanted, add an API route (`src/pages/api/*`) — do not re-inflate island
|
||||
props.
|
||||
|
||||
5. Consider whether `threshold: 0.4` fuzzy matching is too loose for short
|
||||
queries (it now matches typos, e.g. `websit` → match). Tune in
|
||||
`src/lib/search.ts`.
|
||||
|
||||
## Suggested commit (NOT executed)
|
||||
|
||||
```
|
||||
fix(search): read SSR query param, add empty states, slim island payload
|
||||
|
||||
- Use Astro.url.searchParams instead of window (unavailable in SSR) so
|
||||
?search= deep links, refreshes and back/forward restore results
|
||||
- Render explicit "No results" / "Keep typing" states instead of blank page
|
||||
- Move search logic to src/lib/search.ts with Fuse.js fuzzy matching
|
||||
- Stop serializing markdown bodies into island props (43.5 KB -> 25.3 KB)
|
||||
- Guard browser APIs behind onMount; onCleanup previously threw during SSR
|
||||
teardown and 500'd /search
|
||||
- Add 11 vitest unit tests + test script + vitest.config.ts aliases
|
||||
```
|
||||
|
||||
Delete this file once the handoff is consumed.
|
||||
|
||||
Caveats learned the hard way:
|
||||
- `astro dev` backgrounded from the agent shell gets **reaped between tool
|
||||
calls**; starting the built server and curling it in the *same* command works.
|
||||
- `astro dev` may print "Another astro dev server is already running" →
|
||||
`npx astro dev stop`.
|
||||
- `node -e "import('./dist/server/entry.mjs')"` alone exits silently — the
|
||||
adapter only listens if you call `startServer()`.
|
||||
- `vitest` 5 removed the `basic` reporter; use default or `dot`.
|
||||
@@ -74,6 +74,14 @@
|
||||
<path d="M12 5l7 7-7 7"/>
|
||||
</symbol>
|
||||
|
||||
<!-- resume (document with a folded corner and text lines) -->
|
||||
<symbol id="resume" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" viewBox="0 0 24 24">
|
||||
<path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/>
|
||||
<path d="M14 2v6h6"/>
|
||||
<path d="M8 13h5"/>
|
||||
<path d="M8 17h8"/>
|
||||
</symbol>
|
||||
|
||||
<!-- globe -->
|
||||
<symbol id="globe" viewBox="0 0 16 16">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.268 14.0934C11.9051 13.4838 13.2303 12.2333 13.9384 10.6469C13.1192 10.7941 12.2138 10.9111 11.2469 10.9925C11.0336 12.2005 10.695 13.2621 10.268 14.0934ZM8 16C12.4183 16 16 12.4183 16 8C16 3.58172 12.4183 0 8 0C3.58172 0 0 3.58172 0 8C0 12.4183 3.58172 16 8 16ZM8.48347 14.4823C8.32384 14.494 8.16262 14.5 8 14.5C7.83738 14.5 7.67616 14.494 7.51654 14.4823C7.5132 14.4791 7.50984 14.4759 7.50647 14.4726C7.2415 14.2165 6.94578 13.7854 6.67032 13.1558C6.41594 12.5744 6.19979 11.8714 6.04101 11.0778C6.67605 11.1088 7.33104 11.125 8 11.125C8.66896 11.125 9.32395 11.1088 9.95899 11.0778C9.80021 11.8714 9.58406 12.5744 9.32968 13.1558C9.05422 13.7854 8.7585 14.2165 8.49353 14.4726C8.49016 14.4759 8.4868 14.4791 8.48347 14.4823ZM11.4187 9.72246C12.5137 9.62096 13.5116 9.47245 14.3724 9.28806C14.4561 8.87172 14.5 8.44099 14.5 8C14.5 7.55901 14.4561 7.12828 14.3724 6.71194C13.5116 6.52755 12.5137 6.37904 11.4187 6.27753C11.4719 6.83232 11.5 7.40867 11.5 8C11.5 8.59133 11.4719 9.16768 11.4187 9.72246ZM10.1525 6.18401C10.2157 6.75982 10.25 7.36805 10.25 8C10.25 8.63195 10.2157 9.24018 10.1525 9.81598C9.46123 9.85455 8.7409 9.875 8 9.875C7.25909 9.875 6.53877 9.85455 5.84749 9.81598C5.7843 9.24018 5.75 8.63195 5.75 8C5.75 7.36805 5.7843 6.75982 5.84749 6.18401C6.53877 6.14545 7.25909 6.125 8 6.125C8.74091 6.125 9.46123 6.14545 10.1525 6.18401ZM11.2469 5.00748C12.2138 5.08891 13.1191 5.20593 13.9384 5.35306C13.2303 3.7667 11.9051 2.51622 10.268 1.90662C10.695 2.73788 11.0336 3.79953 11.2469 5.00748ZM8.48347 1.51771C8.4868 1.52089 8.49016 1.52411 8.49353 1.52737C8.7585 1.78353 9.05422 2.21456 9.32968 2.84417C9.58406 3.42562 9.80021 4.12856 9.95899 4.92219C9.32395 4.89118 8.66896 4.875 8 4.875C7.33104 4.875 6.67605 4.89118 6.04101 4.92219C6.19978 4.12856 6.41594 3.42562 6.67032 2.84417C6.94578 2.21456 7.2415 1.78353 7.50647 1.52737C7.50984 1.52411 7.51319 1.52089 7.51653 1.51771C7.67615 1.50597 7.83738 1.5 8 1.5C8.16262 1.5 8.32384 1.50597 8.48347 1.51771ZM5.73202 1.90663C4.0949 2.51622 2.76975 3.7667 2.06159 5.35306C2.88085 5.20593 3.78617 5.08891 4.75309 5.00748C4.96639 3.79953 5.30497 2.73788 5.73202 1.90663ZM4.58133 6.27753C3.48633 6.37904 2.48837 6.52755 1.62761 6.71194C1.54392 7.12828 1.5 7.55901 1.5 8C1.5 8.44099 1.54392 8.87172 1.62761 9.28806C2.48837 9.47245 3.48633 9.62096 4.58133 9.72246C4.52807 9.16768 4.5 8.59133 4.5 8C4.5 7.40867 4.52807 6.83232 4.58133 6.27753ZM4.75309 10.9925C3.78617 10.9111 2.88085 10.7941 2.06159 10.6469C2.76975 12.2333 4.0949 13.4838 5.73202 14.0934C5.30497 13.2621 4.96639 12.2005 4.75309 10.9925Z"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.9 KiB |
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import { SITE, LINKS } from "@consts"
|
||||
import { SITE, LINKS, RESUME } from "@consts"
|
||||
import { cn, ACTIVE_NAV_COLORS, isNavActive } from "@lib/utils"
|
||||
import Container from "@components/Container.astro"
|
||||
const { pathname } = Astro.url
|
||||
@@ -30,6 +30,13 @@ const { pathname } = Astro.url
|
||||
</div>
|
||||
|
||||
<div class="buttons absolute right-0 top-1/2 -translate-y-1/2 flex gap-1">
|
||||
<a href={RESUME.HREF} target="_blank" rel="noopener noreferrer" aria-label={`${RESUME.TEXT} for ${SITE.AUTHOR}, opens in a new tab`} class={cn("flex shrink-0 items-center justify-center gap-1.5 h-9 rounded-full pl-2.5 pr-3 text-sm font-semibold", "bg-spaghetti-yellow/70 dark:bg-spaghetti-yellow/15", "stroke-current text-black dark:text-white", "border border-spaghetti-yellow dark:border-spaghetti-yellow/50", "hover:bg-spaghetti-yellow dark:hover:bg-spaghetti-yellow/30", "transition-colors duration-300 ease-in-out")}>
|
||||
<svg class="size-4 shrink-0">
|
||||
<use href={`/ui.svg#${RESUME.ICON}`}></use>
|
||||
</svg>
|
||||
<span>{RESUME.TEXT}</span>
|
||||
</a>
|
||||
|
||||
<a href="/search" aria-label={`Search blog posts and projects on ${SITE.TITLE}`} class={cn("hidden md:flex", "size-9 rounded-full p-2 items-center justify-center", "bg-transparent hover:bg-spaghetti-yellow dark:hover:bg-spaghetti-yellow", "stroke-current hover:stroke-black hover:dark:stroke-white", "border border-black/10 dark:border-white/25", "transition-colors duration-300 ease-in-out", isNavActive(pathname, "/search") && "pointer-events-none", isNavActive(pathname, "/search") && ACTIVE_NAV_COLORS)}>
|
||||
<svg class="size-full">
|
||||
<use href="/ui.svg#search"></use>
|
||||
|
||||
+10
-1
@@ -1,4 +1,4 @@
|
||||
import type { Site, Page, Links, Socials } from "@types"
|
||||
import type { Site, Page, Links, Socials, Cta } from "@types"
|
||||
|
||||
// Global
|
||||
export const SITE: Site = {
|
||||
@@ -51,6 +51,15 @@ export const LINKS: Links = [
|
||||
},
|
||||
]
|
||||
|
||||
// Résumé (external, hosted at resume.spaghet.io). Rendered as its own pill in
|
||||
// the header rather than added to LINKS: LINKS drives the nav list and its
|
||||
// active-page highlighting, and an off-site URL would never match a pathname.
|
||||
export const RESUME: Cta = {
|
||||
TEXT: "Résumé",
|
||||
HREF: "https://resume.spaghet.io/quinn/default",
|
||||
ICON: "resume",
|
||||
}
|
||||
|
||||
// Socials
|
||||
export const SOCIALS: Socials = [
|
||||
{
|
||||
|
||||
@@ -12,6 +12,12 @@ export type Links = {
|
||||
HREF: string
|
||||
}[]
|
||||
|
||||
export type Cta = {
|
||||
TEXT: string
|
||||
HREF: string
|
||||
ICON: string
|
||||
}
|
||||
|
||||
export type Socials = {
|
||||
NAME: string
|
||||
ICON: string
|
||||
|
||||
Reference in new issue
Block a user