This past weekend I was working on setting up a Jekyll blog and importing my Medium posts to it. The process was fairly tedious since you need to…
- Convert Medium posts to Markdown
- Download the images from the Medium post
- Replace the image URLs in the post to URLs on your Jekyll blog
- Strip extraneous information from the Medium posts (title, footer, etc)
- Add the Jekyll frontmatter to the markdown
In order to help with this process, I wrote a Medium to Jekyll conversion tool that automates this entire process:
python medium_to_jekyll.py <path-to-Medium-posts-directory> <path-to-Jekyll-root-directory>
The script does the following…
- Iterate through all .html files in the Medium exported posts directory.
- Download the source images in the
img
tags from Medium posts and output them to animg/
directory in the Jekyll root directory. - Updates all of the image sources in your blog post from Medium CDN URLs to the absolute path of your Jekyll directory (e.g. /img/filename.jpg)
- Strips unnecessary HTML from the Medium posts (header, footer, CSS, etc.)
- Converts the HTML into Markdown (using markdownify)
- Formats the Jekyll frontmatter and prepends it to the converted Markdown.
- Writes the Markdown files into the Jekyll
_posts/
directory with the proper formatting.
Hopefully this will save you some time if you’re trying to import your Medium posts into a Jekyll blog.