2019-11-10
The Great Gatsby Migration
gatsby, wordpress, migration
gatsby, wordpress, migration
Photo by Ray Hennessy on Unsplash
Photo by Ray Hennessy on Unsplash
I finished migrating a WordPress blog, SlightEdgeCoder.com to Gatsby yesterday (2019-11-10).
I will provide a "rough" list to describe what's done, as there is no one specific way to accomplish this and share my experience.
For a specific way to create a Gatsby blog, I will add links in the Resources section.
Because of
I've been working with React and that's what I know. There are other SSG or SSR frameworks, but the documentations and ecosystem made me choose it as the migration needed happen quickly. (I started migration after the site went offline).
Follow steps here up to Move content from one WordPress site to another -> Export from Site A
Note that this exports an XML file, not as markdown.
I've tried Jekyll Exporter but it exported associated images to different folder, not within a folder with Markdown content.
I found it didn't co-located related files (content files and media) thus decided not to use this approach.
I used lonekorean/wordpress-export-to-markdown to convert exported WordPress file from previous step into Markdown files and download media thereof.
It's not a CLI, so you'd need to clone the source.
It's a node application with useful flags for options such as exporting grouped by years, months, etc.
Note that it won't import images in the body unless --contentimages flag is set.
I had all content imported on DEV. DEV has a nice feature to export your content as JSON.
Under Settings/misc, you can export all of your content.
Previous step exports markdown but many frontmatters (such as tags, tags, author, etc.) are missing.
So I created a small node script, dance2die/fix-sungcodes-markdown-frontmatters to merge missing frontmatters from DEV json file.
Gatsby requires some learning curve so I will refer to you to the Gatsby tutorial.
I already had an existing repository, dance2die/sung.codes so I just created v2 branch to start from existing Gatsby site. (v1 was simply using WordPress RSS data to create a static version of it.)
After familiarizing with Gatsby, you can pursue further with following articles (I didn't follow the all the steps in both, just took the parts I needed)
Or, you can do what I did, standing on the shoulders of giants
I knew that Kent C. Dodds (KCD, hereafter) migrated from Medium to Gatsby recently (and took very small part finding issues/typos during migration).
Reference: kentcdodds/kentcdodds.com
KCD has generously made the code open source with MIT, I decided to follow his steps and learn from it as well. You know, he is Kent C. Dodds.
KCD has create a global configuration, which made it easy to apply to the whole site.
It was crucial as the common configurations can be used for site content, SEO, or styling for a consistency and traffic.
References:
I've taken most of his configuration and SEO as well as blog post banner display codes. Doing so made it easy to provide OpenGraph data for SEO and get the consistent configuration data throughout the whole site.
I decided to abandon SlightEdgeCoder.com in favor of sung.codes.
Firat Özcan helped me learn a way to 301 redirect easily with CloudFlare, which is what I did.
Reference: Configuring URL forwarding or redirects with Cloudflare Page Rules
If you need to keep your existing URL, rewrite your URL, instead of redirecting.
Here are the some issues that I've encountered.
To provide a consistent UI, I used Theme-UI as gatsby plugin, gatsby-plugin-theme-ui.
"gists" are shown as raw link, thus I used gatsby-remark-embed-gist but hacked by embedding gist CSS for blog post component.
https://gist.github.com/dance2die/23777b26f792f696237f03b9cbf6e050