· 2 min read · updated
Devlog entries rendered with mdsvex
Picked mdsvex 0.12.8 (stable) to render the markdown bodies. The 1.0.0-next rewrite is still a prerelease.
What we did
- Picked mdsvex 0.12.8 (stable) to render the markdown bodies. The
1.0.0-nextrewrite is still a prerelease. - Called mdsvex from a small
markdown()Vite plugin invite.config.ts, not frompreprocess.extensions: ['.svelte', '.md']stays so Svelte compiles the result. - Added
/devlog/[slug]:entries()and the frontmatter in+page.server.ts, the body component in+page.ts. All 23 entries prerender. - Added
RouteWithoutParamsinsrc/lib/links.tsfor links that go throughresolve()alone.
What I learned
- Vite runs every
order: 'pre'transform hook first, then the normal ones, then'post'. The order of thepluginsarray only matters inside each group. - A filter like
{ id: /\.md$/ }keeps a plugin offfile.md?raw. That import is already a JS module (export default "…") and every transform hook runs on it. - Server load data is saved as JSON, and a component can't be. So the component comes from a universal
+page.ts, which receives the server'sdata. - A lazy
import.meta.globgives one chunk per entry, so the browser only downloads the entry it shows. - The prerenderer only finds linked pages. Nothing links to an entry yet, so
entries()is what builds them. Exclude<RouteId, `${string}[${string}`>drops every route with a parameter.
Problems & fixes
CompileError: `<enhanced:img>` was left openon a Devlog entry that mentions the tag in prose. enhanced-img parses every Svelte file in a'pre'hook, before the preprocessors, so it read the raw markdown. My'pre'plugin runs mdsvex before it, and the tag arrives escaped.- One
context="module"deprecation warning per file: mdsvex 0.12 writes Svelte 4 syntax. The plugin rewrites it to<script module>. - One sourcemap warning per file. Returning
map: { mappings: '' }says "no map on purpose". pnpm checkfailed in Nav, Hero and TeaserCard:RouteIdnow includes/devlog/[slug], whichresolve()can't build without a slug. Fixed withRouteWithoutParams.- The page's CSS seemed missing in the preview. An old preview was still on port 4173 serving stale assets; the new one had moved to 4174.
Links
- mdsvex docs
- Vite: plugin ordering
- Vite: glob import
- SvelteKit: universal vs server load
- SvelteKit: entries
Next
- Prose styles for the rendered markdown, then the
/bitacoratimeline with linked cards.