WordPress to Fastpages
Converting wordpress blogs to fastpages
I'm testing out fastpages - a great new tool that (among other things) let's you write blog posts in Jupyter and host them for free using Github pages. This post documents how I moved my past blog posts across from wordpress (datasciencecastnet.home.blog) into fastpages.
The Steps¶
These are the basic steps I followed:
- Set up a fastpages repository by following the instructions (https://fastpages.fast.ai/fastpages/jupyter/2020/02/21/introducing-fastpages.html)
- Export XML from wordpress. I used the standard process, Tools -> Export -> Export All (https://wordpress.org/support/article/tools-export-screen/) to get an XML file that contains all my posts etc.
- Convert the XML export to markdown. I used https://github.com/lonekorean/wordpress-export-to-markdown. I had to install npm with ‘sudo apt install npm’ and then I placed my XML file in the same folder as the script and ran ‘npx wordpress-export-to-markdown’, following the prompts to create files with the right date format. I chose not to place them in separate folders, and didn’t save images scraped from the post body since this caused an error. You can drop these markdown files into the
_posts
folder of your fastpages repository - they'll appear as soon as it finished building!
Some optional extra steps to deal with images:
- Export the media from my wordpress. The markdown files link to images hosted by wordpress, but these seem to load really slowly. Exporting the images and saving them in a 'wordpress_export' folder within the 'images' folder of the fastpages blog let's you have full control over the images and hosting.
- Change the image references in the markdown posts. There are various ways you could do this, but since this post is a jupyter notebook let's do it with a bit of python code!
# Get a list of posts
import glob
posts = glob.glob('../_posts/*.md')
# replace the image URLs to point to our new images
for post in posts:
s = open(post, 'r').read()
s = s.replace('https://datasciencecastnethome.files.wordpress.com', '{{ site.baseurl }}/images/wordpress_export')
f = open(post, 'w')
f.write(s)
f.close()
Push your changes, and wait a few minutes for the build process to finish. Then check out your shiny new blog!