This is a tale of how this very section - hacks.ash.wine works.
I ❤️ Gists, and I have a habit of posting small stuff/code/discoveries/guides etc. up there so I can revisit them later. (All of my public gists : https://gist.github.com/Ashwinning)
Additionally I use Gistbox, which allows me to categorize/add labels to my gists and find search through them faster.
But not all my gists are important, and most of them aren't useful for other people, so I wanted to archive all the ones that could be potentially useful for others at hacks.ash.wine.
This could have been solved easily by creating a Jekyll repository at Github, and posting stuff there in markdown, but I like being able to have separate Gist repositories for separate things.
That too could be solved by writing a small script to sync my gists with the jekyll, but then
- I'd have to port the Wordpress theme/CSS/etc to a jekyll blog.
- Redo changes to the theme header & footer every time it changed on the wordpress site.
- I wouldn't be able to keep multiple files in their own git repo for each 'hack'.
Also, I've had bad luck with Jekyll (on docker on Windows) before.
To do this, originally, I created a Python script which would go through all my gists, then all my Wordpress posts, then compare if there were any gists that hadn't been posted to Wordpress yet, and post those.
The script searches for a #gistblog
hashtag in the gist description to identify if a gist should be synced, the rest of the hashtags as passed on as Wordpress tags, the remaining gist description is used as the Wordpress post title.
As far as the post content itself was concerned, the script simply posted the gist url as the body of the Wordpress post, and let wordpress handle the embedding.
It worked out pretty well actually! Here's an example of what an embedded post looks like : http://ash.wine/what-a-gist-embed-looks-like/
There's a big problem with this approach - SEO.
There's a chance that Google cannot see/will not index the asynchronously loaded content of the gist.
Well, what's the point of aggregating content for others, if other can't find it when they need it?
The new approach is an iteration over the previous one, but with a couple of new features:
- The application now requests the raw content of each tagged gist, runs it though the Github Markdown Parsing API, and posts the rendered HTML content to Wordpress as the post's body.
- It stores the gist's
id
andupdated_at
attributes as Wordpresscustom_fields
with every post (to track and update posts). - Abstracts configuration settings into a
.settings
file so the script can be easily configured for other blogs.
The biggest downside is that since WebHooks don't work for Gists, the application has to be manually run when changes are made to Gists.
It is still very rough around the edges, and may require tweaking for it to fit your taste/preferences, and the configuration of your Wordpress blog.
The repository is available here : https://github.com/Ashwinning/Gist-Wordpress-Sync
If you want to run this for your own blog and need any help, please feel free to open an issue.