diff --git a/.themes/classic/source/atom.xml b/.themes/classic/source/atom.xml index 403328f..5f404fd 100644 --- a/.themes/classic/source/atom.xml +++ b/.themes/classic/source/atom.xml @@ -7,6 +7,7 @@ layout: null <![CDATA[{{ site.title | cdata_escape }}]]> + {% if site.hub_url %}{% endif %} {{ site.time | date_to_xmlschema }} {{ site.url }}/ diff --git a/Rakefile b/Rakefile index ebffc36..7deec57 100644 --- a/Rakefile +++ b/Rakefile @@ -225,6 +225,16 @@ task :deploy do Rake::Task[:copydot].invoke(source_dir, public_dir) Rake::Task["#{deploy_default}"].execute + + require 'net/http' + require 'uri' + hub_url = "higgsboson.superfeedr.com" + atom_url = "blog.higgsboson/atom.xml" + resp, data = Net::HTTP.post_form(URI.parse(hub_url), + {'hub.mode' => 'publish', + 'hub.url' => atom_url}) + raise "!! Hub notification error: #{resp.code} #{resp.msg}, #{data}" unless resp.code == "204" + puts "## Notified hub (" + hub_url + ") that feed #{atom_url} has been updated" end desc "Generate website and deploy" diff --git a/_config.yml b/_config.yml index 5035c40..f4ca83c 100644 --- a/_config.yml +++ b/_config.yml @@ -103,3 +103,6 @@ google_analytics_tracking_id: # Facebook Like facebook_like: false + +# pubsubhubbub +hub_url: http://higgsboson.superfeedr.com/ diff --git a/source/_posts/2013-01-02-pubsubhubbub-with-octopress.markdown b/source/_posts/2013-01-02-pubsubhubbub-with-octopress.markdown new file mode 100644 index 0000000..f263483 --- /dev/null +++ b/source/_posts/2013-01-02-pubsubhubbub-with-octopress.markdown @@ -0,0 +1,107 @@ +--- +layout: post +title: "Pubsubhubbub with Octopress" +date: 2013-01-02 21:44 +comments: true +categories: superfeedr octopress pubsubhubbub real-time +--- + +In this article I explain how to set up octopress with +[pubsubhubbub](https://en.wikipedia.org/wiki/PubSubHubbub), to get +push-enabled feeds. In my example I use [superfeedr](http://superfeedr.com/), which is free to use. + +After you signup up a hub, in my case [higgsboson.superfeedr.com](http://higgsboson.superfeedr.com), +you have to add a hub reference to your atom feed. + +```yaml _config.yml +# .... + +# pubsubhubbub +hub_url: http://higgsboson.superfeedr.com/ # <--- replace this with your hub +``` + +Insert this line: + +{% raw %} +``` xml + {% if site.hub_url %}{% endif %} +``` +{% endraw %} + +into `source/atom.xml`. So it looks like this: + +{% raw %} +```xml source/atom.xml + + + + <![CDATA[{{ site.title }}]]> + + + {% if site.hub_url %}{% endif %} + {{ site.time | date_to_xmlschema }} + {{ site.url }}/ + + + {% if site.email %}{% endif %} + + Octopress + + {% for post in site.posts limit: 20 %} + + <![CDATA[{{ post.title | cdata_escape }}]]> + + {{ post.date | date_to_xmlschema }} + {{ site.url }}{{ post.id }} + + + {% endfor %} + +``` +{% endraw %} + +To push out updates, you have to ping your hub, this is easily done in your +deploy rake task. + +Add these lines to the end of your deploy task in your Rakefile: + +```ruby +require 'net/http' +require 'uri' +hub_url = "higgsboson.superfeedr.com" # replace this with your hub +atom_url = "blog.higgsboson/atom.xml" +resp, data = Net::HTTP.post_form(URI.parse(hub_url), + {'hub.mode' => 'publish', + 'hub.url' => atom_url}) +raise "!! Hub notification error: #{resp.code} #{resp.msg}, #{data}" unless resp.code == "204" +puts "## Notified hub (" + hub_url + ") that feed #{atom_url} has been updated" +``` + +So you end up with something like this: + +``` ruby Rakefile +desc "Default deploy task" +task :deploy do + # Check if preview posts exist, which should not be published + if File.exists?(".preview-mode") + puts "## Found posts in preview mode, regenerating files ..." + File.delete(".preview-mode") + Rake::Task[:generate].execute + end + + Rake::Task[:copydot].invoke(source_dir, public_dir) + Rake::Task["#{deploy_default}"].execute + + require 'net/http' + require 'uri' + hub_url = "higgsboson.superfeedr.com" + atom_url = "blog.higgsboson/atom.xml" + resp, data = Net::HTTP.post_form(URI.parse(hub_url), + {'hub.mode' => 'publish', + 'hub.url' => atom_url}) + raise "!! Hub notification error: #{resp.code} #{resp.msg}, #{data}" unless resp.code == "204" + puts "## Notified hub (" + hub_url + ") that feed #{atom_url} has been updated" +end +``` + +Now whenever you run `rake deploy`, it will automaticly update your hub. diff --git a/source/atom.xml b/source/atom.xml index 83af3f8..f90081e 100644 --- a/source/atom.xml +++ b/source/atom.xml @@ -7,6 +7,7 @@ layout: nil <![CDATA[{{ site.title }}]]> + {% if site.hub_url %}{% endif %} {{ site.time | date_to_xmlschema }} {{ site.url }}/