If you are attempting to self-host a blogging platform, then this article will be of interest. Here is what we will explore :
Medium allows you to export all your personal blog contents.
The content will be sent as email in a zipped file format. Download and unzip the contents to extract comments, claps, bookmarks, drafts etc. Critical item is the “posts” folder.
We will be using Jekyll static website generator engine and an existing blog theme here. Download the project as zip or clone it in your local system. You will need to remove .git folder if you clone it.
> git clone https://github.com/sumeetbajra/beautiful-jekyll > cd beautiful-jekyll > rm -rf .git
After you have the environment setup, go into the project folder using your terminal and enter
bundle install command. You might be prompted to enter your admin password. After the required packages are installed, go ahead and run the Jekyll project using the command
bundle exec jekyll serve
> cd beautiful-jekyll > bundle install > bundle exec jekyll serve
You should see your blog running at http://localhost:4000
Copy the ‘posts’ folder from the ‘medium-export’ folder which we unzipped in the previous step to our Jekyll project folder. Note that ‘posts’ and ‘_posts’ folders are different folders. ‘posts’ is the one containing our Medium exported blogs and ‘_posts’ is the one used by Jekyll internally.
Note: Medium considers comments/responses as posts so the posts folder will contain the comments/responses made in the original Medium article as separate html files. Since we don’t want to display them in our blog as separate entry, we can go ahead and delete them.
Jekyll reads posts from ‘_posts’ folder which currently contains sample posts.
NOTE: Jekyll project requires our posts in “markdown” format and the articles exported from Medium are in “html” format. The images used in our Medium blogs also need to be saved it locally along with Jekyll Front Matter.
This is a complex process and can be automated by single line of command of Python script.
Go ahead and clone the Python script from here (in the current project folder).
> cd beautiful-jekyll > git clone https://github.com/sumeetbajra/medium-to-jekyll
(In case you are using MacOS, Ubuntu or Debian, Python might already be installed on your system. If not, you can download Python from here. )
If you followed our directory structure, you should have ‘posts’ folder containing all the Medium exported articles and ‘medium-to-jekyll’ folder containing our Python script all inside the ‘beautiful-jekyll’ project. Now go inside the ‘medium-to-jekyll’ folder and execute these commands.
// change directory > cd medium-to-jekyll // setup environment for the script > pip install virtualenv > virtualenv venv > source venv/bin/activate > pip install -r requirements.txt // execute script > python medium_to_jekyll.py --source ../posts --dest ../ --layout post --category blog // exit the python virtual environment > deactivate
Here, --source flag is the directory of the Medium exported ‘posts’ folder and -- dest flag is the root directory of our Jekyll project.
Refresh the page at http://localhost:4000, to see all the Medium articles.
Note: If you don’t see the new posts, stop the Jekyll server and restart it again using
bundle exec jekyll serve command.
The ‘posts’ folder containing Medium exported articles and ‘medium-to-jekyll’ folders are no longer needed. You may move them separate directory outside our Jekyll project or delete them.
// go back to project root directory > cd .. > rm -rf posts > rm -rf medium-to-jekyll
So far, Medium articles are successfully exported and displayed. Next, we need to add the ability to compose, update or delete blog posts from the self-hosted project, with Netlify CMS. Netlify CMS allows to manage articles directly to Github repo. To support this, we need to create a new repository for the blog.
Note: Before you upload the project to Github, you might want to update the site’s _config.yml file. It currently contains dummy information and you will want to replace it with your information before uploading it. You can make other changes too as you may feel necessary. Find more details on Jekyll config file here.
Initialize git in the folder and upload it to the newly created repository.
> cd beautiful-jekyll > git init > git add --all > git commit -m "Initial commit" > git remote add origin firstname.lastname@example.org:sumeetbajra/sumeetbajra.github.io.git > git push -u origin master
After it’s done, give it a couple of minutes for Github pages to deploy your app and you should see the blog up and running at
https://<github-username>.github.io if you are using Github pages. In my case, the site is available at https://sumeetbajra.github.io
Creating Github OAuth app
Now since the Github repository is ready, let’s integrate Netlify CMS. User authentication is based on Github OAuth for which we need to create a new Github OAuth app. Head over to Settings page or you can directly click here https://github.com/settings/developers
Click on “New OAuth App” and fill up the form. For ‘Authorization callback URL’, use “https://api.netlify.com/auth/done”
You will then get redirected to the OAuth app’s page which contains ClientID and Secret. You will need this later.
Creating Netlify app
Go to https://app.netlify.com and login with your Github account. Once logged in, click on ‘New Site from Git’ and select Github.
Here, if you wish to host your Jekyll blog using Netlify too, you need to select the newly created blog repository. Otherwise you are free to select any repository you want. Even an empty repository like this will work which I created for this example. In the next step, leave all the settings as it is and click ‘Deploy site’.
If you are not hosting the Jekyll project on Netlify, keep ‘Build command’ and ‘Publish directory’ empty.
Now we need to connect our Netlify app to Github OAuth. Head over to the Settings page -> Access control -> OAuth
Click on Install provider and select Github as provider. Copy the Client ID and Secret from the Github OAuth app’s page and paste them here.
Next, go to Settings -> Domain Management, click on ‘Add custom domain’.
Add your domain name
<github-username>.github.io and click ‘Verify’ and then click ‘Yes, add domain’ if prompted with new message.
Note your Netlify app’s name. In my case, it is ‘practical-shaw-b147f7’.
If you don’t want to create Netlify app and instead wish to use your own OAuth server, you can use ‘netlify-cms-oauth-provider’ package. The detailed instructions are given in its Github page. You need to replace ‘https://api.netlify.com/auth/done’ in the Github OAuth app settings with your own server callback url in this case.
Now let’s go back to our project. We need to create a new folder inside our blog called ‘admin’. Inside it, create two files namely ‘index.html’ and ‘config.yml’. This ‘config.yml’ file is different from ‘_config.yml’ file that is in the root folder. The content for each file is provided below.
In the config.yml file, replace ‘repo’ with your Github repo and ‘site_domain’ with your Netlify app’s domain
<your-netlify-app-name>.netlify.com (skip this in case of custom OAuth).
If you want to know more about what each attribute in the config.yml file does you can check it out here.
Save the changes and then push them to Github. We are done now. If you head over to
https://<github-username>.github.io/admin, you should see Netlify CMS’s login page like this.
Note: It might take couple of minutes for Github pages to update.
Go ahead and login with your Github account and you will be redirected to the CMS’s dashboard which contains all your posts. You can manage your blog posts from here.
If you wish to use custom domain, you can either
<github-username>.github.iowith your DNS provider.
Obviously, these are just in regards to this tutorial. You have the flexibility to customize the project as much as you want and host them wherever you prefer to.
Thanks for following through. I hope you liked the article. If you want to read more of Botsplash team contributions, check out articles here.
Want to learn more about Botsplash platform? Write to us here.
Botsplash, is an innovative, digital messaging software with the ability to connect agents and customers across any digital platform. In order to win and keep a customer’s business, businesses must be able to connect with customers in a meaningful way using websites, social media, text and email. Botsplash helps businesses adopt digital strategy with right balance on Live Chat and Automation.