Automating Image Hosting for Markdown
I used to put my images on sm.ms, a public image host with an open API. I even wrote a script to upload the images and replace the links in my Markdown. The service’s limits became frustrating, though: uploads were restricted per minute and capped at 20 images per hour. I decided to host them in my own GitHub repository instead and consider a VPS later.
I wrote another script to automate the new workflow: paste image -> put image in git folder -> run automation script. The script handles the upload and link replacement. Here is how I set it up.
First, set up a directory in a GitHub repository to hold the images:

Then use git clone to make a local copy:

Put your images in that local directory. In typora, you can also set it as the automatic image-save location; that skips the manual copy and lets you run the script immediately.
Open the script and adjust the paths and repository settings for your own setup:

I marked the settings that need changing in comments in the code below.
Once those settings are in place, running the script completes the upload and link replacement. Here is the automation code:
1 | import re |