Why and what?
I like webby and the idea of having a blog with static pages, not that I ever think I need the speed of it but I at least save some RAM on a daily basis. :)
So this gem can send pingbacks and also receive pingbacks through Disqus. What we’re actually doing when receiving is just validating it as a pingback and then send a trackback to the Disqus page for the post.
Usage
Make sure that all your posts that you want to be able to ping other sites have a meta-data key that is called pingback_done and set it to false. When the ping has been done, successful or otherwise, it will be set to true. Example meta-data:
---
title: a spiffy blogpost
[..]
blog_post: true
pingback_done: false
---
Write your post, deploy and then run:
webby pingback:ping
Note: You’ve to deploy because of how the pingback protocol works, the receiving end must be able to retrieve the page trying to send it a pingback
Installation
Install it through rubygems:
gem install ba-webby-pingback --source http://gems.github.com
This library depends on these gems:
amalgalitefor SQLite database supportjsonfor parsing received JSON-data from Disqushpricotfor parsing HTML-sites and finding whether there’s a link to your site in the pingback receiver
Installing the sender
Now you’ve to install the rake tasks. Do this by either copying the pingback.rake file from the gem installation directory or create a new file with this content:
require 'webby-pingback-rake'
Loquacious.configuration_for(:webby) do
desc 'The find attributes to search for new blog posts to ping with the webby-pingback gem'
pingback_find [:all, {:blog_post => true, :pingback_done => false}]
desc 'The xpath expression used to find links in your new post to ping with the webby-pingback gem'
pingback_find_links_expression '/html/body//a[@href]'
end
Remember to change the configuration options to suit your needs. :)
You also have to set the SITE.base option in your Sitefile which together with your blog posts gives the task an absolute URL to your post. Without it the sender won’t be able to send URLs that the receiver can do a lookup on and your pingbacks will not be received.
SITE.base = 'http://example.com/blog'
Installing the receiver
To receive pingbacks you’ve to run a script that can act as a XML-RPC server, I’ve written a CGI-script using Rubys built-in XML-RPC package (which also can run it as a standalone server or WEBrick servlet), which can be used with a CGI-script that looks like this: (a copy exists in the ext folder)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$KCODE = 'u'
module Pingback
Conf = {
:db => 'path-to-sqlite-datbase-that-is-writable-by-server'
:forum_api_key => 'long string from disqus, use rake task to get'
}
end
require 'rubygems'
require 'webby-pingback-xmlrpc.cgi'
Note: The pingback database, a sqlite database, has to be writable by the server running the cgi-script. The database will be created if it doesn’t exist, so you don’t have to do anything to create it. The database is used to record incoming pingbacks so that we don’t send multiple trackbacks to Disqus for the same link.
To get the Disqus forum api key you can use a rake-task that is included in the rakefile for this gem. Just run:
webby pingback:fetch_disqus_forum_key
The user key which the task asks for you can get at http://disqus.com/api/get_my_key/ when you’re logged in to Disqus.
When the CGI-script is setup and is working you only have to add a <link> tag to your blogposts that points to the CGI-script and we’re done:
<link rel="pingback" href="http://example.com/cgi-bin/pingback-xmlrpc.cgi.rb" />
Setting up CGI with Lighttpd
To get CGI-scripts to work with ligghttpd you just have to activate the CGI module and then tell lighty the path to where you store the script, aka the cgi-bin directory.
Note that the receiver proxy doesn’t in any way require webby, so if you have any other static site you can as well use this script to get pingbacks with Disqus. :)
server.modules += ("mod_cgi")
alias.url += ("cgi-bin" => "/var/www/cgi-bin/")
cgi.assign = ("" => "")