· 2 min read · updated
Blog drafts that never ship
Moved every post to content/blog/drafts/. A post is a draft because of where it lives, so Entry.draft comes from the path and the draft: true frontmatter is…
What we did
- Moved every post to
content/blog/drafts/. A post is a draft because of where it lives, soEntry.draftcomes from the path and thedraft: truefrontmatter is gone. - Wrapped the drafts glob in
import.meta.env.DEV ? import.meta.glob(…) : {}, incontent.ts(frontmatter) and inblog/[slug]/+page.ts(bodies). - Built
/blog(posts grouped by year withMap.groupBy) and/blog/[slug]the same way as the Devlog. Both[slug]pages now shareArticleHeader.svelte. - Added a
prerender.handleUnseenRouteshandler that ignores only/blog/[slug].
What I learned
- Hiding a draft with a filter isn't enough. A glob is resolved when the site builds, from file paths only, before any frontmatter is read. Vite makes a chunk for every file it matches, so a filtered draft would still sit in
build/_app/immutable/as a public.jsfile. - In a build, Vite replaces
import.meta.env.DEVwithfalse, and the dead branch is removed with the glob inside it. No draft is read or bundled. - A server
loadreturns data that gets serialized (devalue), and a component is a function, so it can't be. That's why the body comes from+page.ts, a universalloadthat canimport()the chunk in the browser too. - Two checks catch different link problems: a link to a missing page fails the crawl (and
resolve()with a typo fails in TypeScript), andhandleUnseenRoutescatches a route nobody links to. I kept the check on for everything except/blog/[slug], which has no pages until a post is published.
Links
- Vite: Glob import
- Vite: Env variables
- SvelteKit: Universal vs server load
- SvelteKit: Configuration, prerender
Next
- Syntax highlighting with Shiki.