· 3 min read
A CV builder whose form remembers
/projects/cv: pick a profile, fill in name, surnames, phone, email, city, state, postal code and a short letter, and a CV next to the form follows: name…
What we did
/projects/cv: pick a profile, fill in name, surnames, phone, email, city, state, postal code and a short letter, and a CV next to the form follows: name, profile, contact line, Summary (the letter), then the profile's skills by group, strongest first.- The skills come from
content/skills.yaml, cut down on the server (src/lib/projects/cv/skills.server.ts): names and profiles only. A skill without a level prints its note's first sentence: "Spanish (Native)". - The CV builder has its own route,
src/routes/projects/cv/, with a+page.server.ts.projects.ts'toolis optional now,[tool]'sentries()skips tools without one, and the page header isProjectHeader.svelte, shared by both routes. - My details live in
CvDetails(details.svelte.ts), a$stateclass kept inlocalStorage. Nothing reaches the repo, the build or a server.
What I learned
- SvelteKit prefers a fixed route over a
[param]one, so/projects/cvbeats/projects/[tool]. A route of its own gets server data with its exact type, instead of an optional prop on every tool. - One
$stateobject for the whole form: it's a deep proxy, sobind:value={cv.values.name}works andJSON.stringifysees every field. Separate$statefields on a class are getters on the prototype, andJSON.stringifywould give{}. localStorageis read inonMount: it doesn't exist while prerendering, and loading before hydration would make the first render differ from the HTML.read(data: unknown)keeps only known fields, only strings, only a profile that exists. Storage belongs to the origin (abafdez.github.io, shared by all my Pages projects), so it can hold anything.- Saving is an
$effect: keeping something outside Svelte in step with the state.save()reads every field, so any change reruns it. Theif (cv.loaded)guard stops the empty form overwriting what was saved, whatever order the effects run in. autocompletevalues (given-name,tel,postal-code…) let the browser fill the form. A form without anaction"submits" its fields into the URL, soonsubmitprevents it. A disabled<fieldset>disables every field in it.
Problems & fixes
- Changing the profile saved the previous one. The form saved on
oninput, but a<select>firesinputbeforechange, and Svelte updatesbind:valueon a select atchange. The$effectdoesn't depend on event order. - The first test showed 14 errors: a preview server from before the rebuild was still on port 4173, serving the old file list. Restart the preview after every build.
Links
- Svelte:
$effect - Svelte:
$state(deep state) - SvelteKit: route sorting
- MDN: localStorage
- MDN: autocomplete
Next
- Print: a button and a print stylesheet for an ATS-friendly PDF. Then native form validation, editing the skills, and JSON import/export.