· 2 min read
Videos in posts
Videos next to a post, written as HTML in the markdown (<video>, <source>, <track>, poster). The markdown step turns every ./ src or poster into an import, so…
What we did
- Videos next to a post, written as HTML in the markdown (
<video>,<source>,<track>,poster). The markdown step turns every./srcorposterinto an import, so the build gives it a real, hashed URL and fails if the file is missing. - A
<video>withoutwidthandheightfails the build, like an image without alt text: without them, the page jumps when the video loads. enhance-images.tsis nowenhance-media.ts(enhanceMedia()), with five new tests (11 in the file)..prosestyles videos like images (border, radius, scaled down withblock-size: auto).- The publishing guide has a Videos section: MP4 and WebM, the attributes, and the ffmpeg commands to compress a recording.
What I learned
- An animated GIF in a post would come out still: enhanced-img opens files with
sharpwithout asking for animation, so only the first frame is kept. A video is also much smaller, and can be paused. - Vite already treats
.mp4,.webmand.vttas assets: a plainimport clip from './clip.mp4'gives the hashed URL. Videos are used as they are, not re-encoded, so compress them before committing. - With several
<source>s, the browser plays the first one it can: WebM (smaller) first, MP4 (plays everywhere) last. mutedmatters to Svelte: it warns about a video without a captions<track>, unless it's muted.- Playwright can record a browser as WebM (
recordVideo), handy for a test video.
Links
Next
- Record the Awesome list jumping (from the commit before the fix) for "Pages that jump".