This blog is handcrafted with markdown files in vim. Up until now, posting images was a prohibitive dance of putting the image on a certain folder and figuring out the relative path, posting it into markdown and then adjusting a few times until I got it right.
Which is the reason why I never posted any.
Yesterday I implemented https://github.com/img-paste-devs/img-paste.vim 1 and now I can paste images directly.
If you see the below image, it works!
Now the steps to add an image to a post are:
Cmd+Ctrl+Shift+4
on a mac<Leader>p
to paste the image (my leader key is comma, so in my case, ,p
)This will create a png file in the directory you specify, and add the right markdown syntax to the file.
Here is a quick video explaining how it works:
Instructions on the plugin page are clear. Here are a couple of adjustments I had to make to match to my workflow
By default, the plugin stores the image in an img
subdirectory inside the same folder
as the markdown file. In my case I wanted to move it to my /public/images folder at the root of my
site.
let g:mdip_imgdir = '../public/images'
I have added that to a .vimrc.local
file In the root of the project, since this
configuration is specific to this project.
The above variable creates a url that is relative to the markdown file, which is perfect for when you're previewing the markdown file with an external tool or withing github.
But in Next.js (which is what I use for this website), the /public folder is served as the root of the website (so /public/images is just /images).
To solve this, I added a simple regex that rewrites the links when rendering
Here's a few improvements I'm thinking of:
And that's it. If you have comments questions or suggestions please let me know! @jesusollonet on twitter (or pretty much anywhere) or email me at here.
Oh god I had to add the markup to this link manually!! Next one. ↩