· John Dummy · 1 min read
VSCode Image Paste Support
Learn how to use VSCode's native image paste feature for a seamless authoring experience.
This blog implements a seamless workflow for adding images to your posts using VSCode’s built-in image paste functionality. This allows you to focus on writing without worrying about manual file management.
Authoring Workflow
- Open a Markdown file: Open any post in the
src/data/post/directory. - Paste an image: Copy an image to your clipboard and paste it directly into the Markdown editor (
Cmd+VorCtrl+V). - Automatic placement: VSCode will automatically:
- Save the image into a subfolder:
images/<post-name>/<image-name>.png. - Insert a correctly formatted link:
.
- Save the image into a subfolder:
How it works (The Build Pipeline)
When you run bin/deploy, the blog-code repository performs the following behind the scenes:
- Consolidation: Any images found in
src/data/post/images/are moved to the centralsrc/assets/images/directory. - Path Rewriting: The relative paths in your Markdown files are dynamically rewritten from
images/...to../../assets/images/.... - Optimization: Astro’s image service takes over, converting your images to modern formats like WebP and applying responsive compression for faster page loads.
Benefits
- Clean Content Structure: Images for a specific post are neatly grouped in a folder named after the post.
- VSCode Preview Compatibility: Because the paths are relative, images display correctly in the VSCode editor preview.
- Source Integrity: Your original files in the
blog-contentrepository remain untouched; optimization and path rewriting occur only during the build process.