Add Hero Image to Blog Post
Convert a source image to WebP format and add it as a hero image to a blog post.
Arguments
- •
$1- Path to the source image (e.g.,~/Downloads/my-image.png) - •
$2- Post slug (e.g.,the-layer-above). If omitted, infer from the image filename.
Steps
- •Locate the post at
src/content/posts/$2.mdorsrc/content/posts/$2.mdx - •Convert the image to WebP using ImageMagick:
code
convert <source> -quality 80 src/content/posts/<slug>.webp
- •Report the size reduction (original size vs converted size)
- •Add the frontmatter field
heroImage: ./<slug>.webpto the post (add it after thetagsline if present, otherwise before the closing---) - •Verify the build with
pnpm run build