From Ugly to Beautiful
martinkysel.com
martinkysel.com
The Programmer’s Credo:
”We do what we do; not because it is easy, but because we thought it would be easy.”
I have considered migrating my sites from WP, but they aren’t really central enough to my work, to justify the effort.
WP lets me keep a fairly “hands off” approach, while also giving me a great deal of control over things like formatting.
But the new MD-based static site generators are pretty cool, and I may get around to it.
> Per the primary purpose of the plugin...it can mostly be considered a beta testing plugin.
It took 6-8 weeks, and I was on a roadtrip for 3 of those. It includes writing a SSG from scratch and migrating both the content and the templates.
I'm about to write my own recap, but to summarize it here: it went okay, and I love working with markdown.
The biggest issue was the conversion of 5 years of HTML noise caused by Redactor, a WYSIWYG editor with many quirks. The converter didn't know what to do with stray line breaks at the end of block elements, among other oddities. I had to fix a lot of stuff manually.
The second biggest issue was implementing responsive images with captions, which replace img tags with elaborate figure elements. I converted those to markdown manually, then wrote my own markdown extension. It wasn't that bad!
I've now been editing markdown for a month, and I am loving it. It's text in files, not HTML in a database. You can transform it with an arsenal of tools from the last 5 decades, not just a crummy WYSIWYG editor. You can apply the same rigour to the written word as you would to code. You can use scripts, regex, linters, and fancy text editors with fine-tuned plugins and themes. It's awesome to have so much control over your work environment.
It's also great to review changes with a git merge tool, to deploy content updates like code, to work offline on slow hardware.
Oh and the server has so few moving parts now. No more WordPress updates, no MySQL CPU spikes. The whole thing is so simple.
I waited a long time to move to an SSG, but it was absolutely worth it.
> The biggest issue was the conversion of 5 years of HTML noise caused by Redactor, a WYSIWYG editor with many quirks. The converter didn't know what to do with stray line breaks at the end of block elements, among other oddities. I had to fix a lot of stuff manually.
For anybody else trying this sort of rewrite, don’t rule out automating a (headless) browser in place of digesting noisy source files. The browser is designed to normalize a lot of that awful input content to a sane DOM, and you can then extract your clean markdown/whatever representation from that normalized content tree rather than from a raw HTML model (with all its loosey goosey allowances).
And if this is your own project/code, you might also introduce a few changes into your CMS template to make the scraping more reliable.
The nice part is that I could fix those issues with regex. I could fix hundreds of page in a few keystrokes, and only commit changes if they looked right. I also fixed thousands of little things that were impossible to fix before, because editing text files is trivial.
To migrate the content, I converted the templates to output plain markdown files instead of HTML. I also had one page that was a plain text list of all entries to migrate. A script read the list and saved each rendered markdown file.
I can't overstate how pleasant it is to work with plain text files. Today, I'm reviewing 450 locations with the Google Places API. I fixed a dozen businesses that moved or closed. This would have taken days before. It was to tedious to even try.
I have had bad, bad luck with site builder/WYSIWYG editors (and not really that much luck with Gutenberg).
I'm quite fortunate, in being able to write page code/CSS. Also, my sites aren't really very active, so it's not such a big deal, for me.
I know the Medium CEO likes to lurk in these threads: I'd suggest that making Medium a viable replacement for sites that give their managers a great deal of control over presentation, could be a great idea. I'm fully aware of the enormity of that task. Just figured I'd put it out there.
It's just that it still inserts weird markup, especially when pasting things. I had the worst time removing unprintable characters.
It is true: Migrating ~10 years worth of Wordpress mess to markdown that can be slurped in by something like Gatsby was a pain in the arse in my case. So many strange little things regularly broke that I’m pretty sure some are still broken. Naturally I no longer had source files, just what was live in Wordpress.
Also a word of warning – host images yourself. So many lost images (and links) on my site due to link rot. Makes me sad
But I now have all my content in text files on a github repository. The next migration will be easier.
Any modern wp set-up should have great caching and performance?
Of course, there are issues with wp that may make it worthwhile to move away - but costly hosting, outdated design or low performance shouldn't be among them?
I would argue that if you want to make changes to a system, such as a migration, its the perfect time to rethink it.
> And at the end of the day, you still have to deal with WP.
Certainly - I'm not saying one should not migrate away from wp - just be sure you make an informed choice...
I just now saw this bit in the original article:
> The cost of a properly hosted server, combined with the need for a distributed database (...)
I'm not sure what "distributed database" means here - but I'm quite certain wp and mariadb/postgres will run fine together on a 5 dollar vps - if something like Dreamhost isn't attractive for some reason.
That said - i too would much prefer something like github pages for a blog.
Literally hundreds of thousands WP hosting sites
I get that it's not always a cost exercise and more exploratory learning to change your blog around, but that stuck out as an odd complaint when justifying a shift in your stack.
So.. is it still hosted in your friends basement?
WordPress requires more babysitting.
> Privacy Badger has replaced this Disqus widget
This reminded me that self hosting with WP or equivalent software means to own the comments and the burden to spam filter them. With static sites it's either no comments, self hosting them (don't know how) or hosting them at Disqus or similar platforms.
TL;DR: Hugo is amazing for static websites and blogs. I host mine on Vercel and it auto-builds to my production TLD in under 5 seconds.[3]
[0] https://dev.to/whyboris/migrating-wordpress-to-gatsby-in-3-s...
[1] https://github.com/whyboris/yboris.com