Static Markdown for websites
While working with static markdown for websites, there are several difficulties.
- WYSIWYG images. You either work with something like

that does not render in your editor and makes it hard to add and delete images. Or with
which compiles into<img src="image.png" alt="alt" />
and forces you to keep everything flat inpublic/
or something. - Image caching.
image.png
should be cached on CDN. Changing its contents should bust the cache. - Image speed. Ideally
image.png
should be compiled towebp
as well, leveraging modern browsers.
To fix these I made a small script.
Meet organize-md
You can add it to your project with:
yarn add organize-md -D
Next, create a config.yml
for it:
contentDir: blog/
mdOutDir: public/blog/
imgOutDir: public/images/blog/
imgURLPrefix: /images/blog/
yarn organize-md config.yml --watch
With this setup, each Markdown document should be placed in its own folder. Following this organization,
some text 
will be transformed into:
some text 
This new format allows your images to be cacheable. In the future, the package will also support compilation to webp
.
A Note on Image Caching
For your imgURLPrefix
, be sure to add a Cache-Control
header. For instance, if you're using Cloudflare Pages, add
the following to your public/_headers
file:
/images/*
Cache-Control: public, max-age=31536000, immutable
For Next.js, add this to your next.config.js
headers()
array:
;[
{
source: "/images/*",
headers: [
{
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
},
],
},
]
You'll find that most frameworks support this functionality.
Wrapping Up
By streamlining Markdown content management and making your site faster, organize-md
allows you to focus on what
truly matters — content itself.