Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775
{"id":274,"date":"2016-11-16T12:31:00","date_gmt":"2016-11-16T07:01:00","guid":{"rendered":"http:\/\/ash.wine\/?p=274"},"modified":"2016-11-18T15:27:20","modified_gmt":"2016-11-18T09:57:20","slug":"gist-wordpress-sync","status":"publish","type":"post","link":"http:\/\/hacks.ash.wine\/gist-wordpress-sync\/","title":{"rendered":"Gist – WordPress Sync"},"content":{"rendered":"
\n

\n<\/span><\/a>Gist – WordPress Sync<\/h1>\n

This is a tale of how this very section – hacks.ash.wine<\/a> works.<\/p>\n

I \u2764\ufe0f<\/g-emoji> Gists<\/a>, 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<\/a>)<\/p>\n

Additionally I use Gistbox<\/a>, which allows me to categorize\/add labels to my gists and find search through them faster.<\/p>\n

\"\"<\/a><\/p>\n

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.<\/p>\n

\n<\/span><\/a>Problems and Solutions<\/h2>\n

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.<\/p>\n

That too could be solved by writing a small script to sync my gists with the jekyll, but then
\n1. I’d have to port the WordPress theme\/CSS\/etc to a jekyll blog.
\n2. Redo changes to the theme header & footer every time it changed on the wordpress site.
\n3. I wouldn’t be able to keep multiple files in their own git repo for each ‘hack’.<\/p>\n

Also, I’ve had bad luck with Jekyll (on docker on Windows)<\/a> before.<\/p>\n

\n<\/span><\/a>The Original Solution<\/h2>\n

To do this, originally, I created a Python script<\/a> 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.<\/p>\n

The script searches for a #gistblog<\/code> 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.<\/p>\n

\"\"<\/a><\/p>\n

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.<\/p>\n

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\/<\/a><\/p>\n

\n<\/span><\/a>The Problem<\/h2>\n

There’s a big problem with this approach – SEO.<\/p>\n

There’s a chance that Google cannot see\/will not index the asynchronously loaded content of the gist.<\/p>\n

Well, what’s the point of aggregating content for others, if other can’t find it when they need it?<\/p>\n

\n<\/span><\/a>Introducing Gist-Wordpress-Sync 2.0<\/h2>\n

The new approach is an iteration over the previous one, but with a couple of new features:<\/p>\n

    \n
  1. The application now requests the raw content of each tagged gist, runs it though the Github Markdown Parsing API<\/a>, and posts the rendered HTML content to WordPress as the post’s body.<\/li>\n
  2. It stores the gist’s id<\/code> and updated_at<\/code> attributes as WordPress custom_fields<\/code> with every post (to track and update posts).<\/li>\n
  3. Abstracts configuration settings into a .settings<\/code> file so the script can be easily configured for other blogs.<\/li>\n<\/ol>\n

    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.<\/p>\n

    It is still very<\/strong> rough around the edges, and may require tweaking for it to fit your taste\/preferences, and the configuration of your WordPress blog.<\/p>\n

    The repository is available here : https:\/\/github.com\/Ashwinning\/Gist-Wordpress-Sync<\/a><\/p>\n

    If you want to run this for your own blog and need any help, please feel free to open an issue<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

    Gist – WordPress Sync This is a tale of how this very section – hacks.ash.wine works. I \u2764\ufe0f 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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/274"}],"collection":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":1,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":275,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/274\/revisions\/275"}],"wp:attachment":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}