This is a modified fork of bgadrian/medium-to-hugo.
Reads a given Medium export archive, and converts the HTML contents of the posts
directory into Hugo compatible Markdown files.
Most of the functionality from upstream are preserved, however the underlying details are somewhat different.
The features preserved from the upstream are,
- SEO friendly (keeps the old URL as an alias)
- Populates Hugo FrontMatter with relevant details
- Converts drafts and marks them specifically
- Fetch the article TAGS (which are not included in the Medium exporter), compatible with Hugo Related feature
- Fetch all the Images
- Stories are ordered by date (
year-month-day_slug
) - Custom
.Params
: image, images, slug, subtitle - Minimal HTML cleanup (removed empty URLs, duplicate title and so on)
- Adds
#layout...
suffix to every image so they can be styles accordingly from plain CSS with exactly same style as on Medium.
Following are the fork specific features.
- Converts and writes all Markdown in the same directory, unlike the upstream project which creates a directory for each post
- Downloads images into one directory instead of a directory inside the post-specific directories
- Does not ignore comments
- Will ignore empty articles based on a flag (
-e
) - Any self-references (links that point to articles by the same author) are fixed so that after conversion they point to the converted site
- Read and convert Github Gist embeds into Markdown code blocks with relevant syntax highlighting
- Convert preformatted code blocks correctly by parsing embedded line break tags
- Corrects Medium export glitch where an empty line within a preformatted block generates two preformatted blocks
- Convert Slideshare Medium embeds to HTML embeds within Markdown.
- Convert Twitter Medium embeds to Tweet embeds (using Hugo Shortcodes)
- Handle edge cases like bolded inline code which doesn't get converted well during Hugo site generation
- Render
figcaption
- Customized footer from Medium export information
The use of Hugo shortcodes as a way to embed external resources like Gists were kept to a minimum to keep the Markdown generation reusable across different static site generators.
- Download your medium data
- Download the latest
m2h
binary, to a suitable place - Run
m2h
binary providing the path to the Medium extract. Provide flag-e
if empty articles should be ignored. m2h
will create a directory in the current working directory namedmedium-to-hugo_<date>_<time>_
. The converted files will be in theout
directory inside.
# convert all posts from this medium extract
./m2h -f medium-export.zip
# convert all but empty posts
./m2h -f medium-export.zip -e
You need Bash, Go 1.11+
- Clone this repository, and checkout a specific commit if wanted to.
- Use the
Makefile
to build. If at version 2.0 tag or later, usemake release
to cross compile binaries forlinux
,windows
, anddarwin
. For previous versions usemake buildall
.
Submit issues, PRs using Github. Please use the upstream project if your requirements seem to match it. This fork has changed with my personal opinions. If you think your improvement matches the upstream project more than this, please contribute there.
Untested in Windows and Mac
- bgadrian/medium-to-hugo - The upstream project
- gautamdhameja/medium-2-md
- The first Gist - The Gist that was used as the inspiration by the upstream project