Today, I finished migration of my blog https://prahladyeri.com from a self-hosted Wordpress site to a statically hosted Github Pages site. For the static site generator, instead of choosing Jekyll which is a hot favorite of rubyists, I went for Pelican instead as I figured my Python skills might be somewhat useful in dealing with that.
Having used Jekyll earlier, I felt that Pelican is pretty much the same thing. There is a configuration file in which you define your site parameters, a folder hierarchy for defining your posts and pages, and a bunch of templates (
pelican theme) to make some serious customizations.
In this post, I'll briefly go through the migration process:
- Run the standard Wordpress import tool and backup all your posts and comments. Its better if you disable comments on your site (or maybe even take it down entirely for maintenance until the migration is complete).
- Copy the
uploadscontaining your images through FTP/SFTP.
- Install Python on your machine if not already.
Install the Pelican and Markdown packages:
pip install pelican markdown
Install additional packages for importing the Wordpress XML:
pip install BeautifulSoup4 lxml
pandocas its needed for
markdown-xmlconversion during the Wordpress import. Instructions for installing it for your OS can be found here.
- Create a new folder (such as
PRAHLADYERI.COM) for your new blog writing/publishing.
Traverse to that folder through command line and run
pelican-quickstart. It'll ask some basic questions like your blog name, title, etc. You can leave most to their defaults. Once done, it'll create a folder structure like below:
d:\source\PRAHLADYERI.COM ├───content │ ├───pages │ ├───uploads │ │ ├───2016 pelicanconf.py tasks.py MakeFile
MakeFileare something you can ignore unless you want to automate site generation. Now you can copy the
uploadsfolder brought from Wordpress inside the
contentfolder (its the place where your posts will now reside in either markdown (
.md) or reStructured Text (
- Copy the XML file imported from Wordpress inside the main folder (
PRAHLADYERI.COMin my case).
Now simply run
pelican-import --wpfile -m markdown <your-file.xml>
The above command converts all your Wordpress posts (not comments) into markdown format and copies it to the content folder. Your old site is now imported to the pelcian system and is ready for generation!
- Make some changes to the
pelicanconf.py. Set the attributes for
SITENAME. You may also want to set
ARTICLE_URL_SAVE_ASto match your existing site's URL pattern.
To generate the new site, simply run:
This will generate a folder called
outputwhich you can directly serve through github pages! You can also go to the output folder and test it locally by running this command and checking in your browser:
python -m http.server
This is the very simplest of use-cases, of course. For other advanced things like changing the theme templates and CSS, migrating to disqus comments, etc., I'll make another post later. If you are in a hurry, then you can refer the official pelican docs which has all these details and a lot of other useful information.