Skip to content

How to clone medium story into custom domain

  • by

Duplicate your medium content on your own site using jekyll and feedjira

Perquisites: see article https://medium.com/@kusumandaru/create-personal-website-on-second-152339342b7c to step by step detail how to set and publish site.

As we know since November 2017 medium will not accept custom domain as part of medium. How if we want to took our content from medium and move it to our personal domain with only cost custom domain in nowadays.

Disclaimer: rather than publication will be hosted on Medium, it still using own hosting, i prefer github pages to hosting static page, cause it’s free and simple.

First of all we need Jekyll and specific template, i use template mediumish since it have sleek design and more relevant with medium design. It also have additional configuration for comment, google analytic and featured image.

Since it using markdown file (.md) as source of article

---
layout: post
title: "Cool title"
author: angga kusumandar
categories: [ Jekyll, tutorial ]
image: assets/images/5.jpg
description: "Something about this post here"
---

we create md file from rss of medium, example https://medium.com/feed/@kusumandaru, we can grab it and transform into md file. Take a note if each rss have ten latest article, and it can generate new one if new article medium exist, for old article you need create md file manually.

url = "https://medium.com/feed/@#{username}"
xml = ::HTTParty.get(url).body
feeds = Feedjira.parse(xml)
feeds.entries.each do |entry|
  p "Title: #{entry.title}, published on Medium #{entry.url} #{entry}"
  create_file(entry, site)
end

first we try to get rss and get entries data

def image_url(content)
  doc = Nokogiri::HTML(content)
  doc.xpath("//img")[0]['src']
end

we also parse image using Nokogiri to get first image from each article to convert as feature image

path_file = "./_posts/" + published.strftime('%F') + '-' + title.parameterize.first(15) + ".md"
path = site.in_source_dir(path_file)

and than we create file with publish data and title to make unique and sort article by date

File.open(path, 'wb') do |file|
  file.write "---"
  file.write "\n"
  file.write "layout: post"
  file.write "\n"
  file.write "title: #{title}"
  file.write "\n"
  file.write "author: #{author}"
  file.write "\n"
  file.write "categories: #{category}"
  file.write "\n"
  file.write "image: #{image}"
  file.write "\n"
  file.write "---"
  file.write "\n"
  file.write content
end

and then we create content of md file with spesific format and content

After that try to publish static page using JEKYLL_ENV=production bundle exec jekyll build. also on spesific md file, add feature: true to make artice published on top of index page. Finally publish site page in github page.

And voila your website now consist medium content.

You can see full repository code here

final website

Leave a Reply

Your email address will not be published. Required fields are marked *