In crowbar-ing in webmentions I realised that the syndication code I’d written need overhauling if I was ever going to support more than u-in-reply-to. In fact, so much so that the code in my note syndication post is now obsolete; rather than looping through the posts in the syndication method of each syndication class instance I’m doing the looping just once in the Rakefile and calling the correct syndication class as required.

That overhaul was time consuming and explains the lack of posts here this month - I’ve spent most of my time doing behind-the-scenes work - but things are much cleaner now; although as ever, there is always room for improvement: I am still only webmentioning u-in-reply-to, but it will be easier to add it in for other uses of webmention.

In the Rakefile, when looping through posts, I do this when I come across a new link post since last deploy date:

case yaml["type"]
	when "link"
		post_data["link"] = yaml["link"]
		@posse_pinboard.syndicate(post_data)
		#For the time being webmentions are only sent for link type posts that have this key
		if yaml.has_key?("u-in-reply-to")
			@webmention.send(post_data)
		end
	when "photo"
		#Different things
	#And so on
end

Simple. The actual sending of the webmention is just as easy. I’m using Nokogiri to find the webmention endpoint (As far as I know it will only ever be on link element):

def find_webmention_endpoint(post_url)
	#Should cache these? Probably not worth it.
	page = Nokogiri::HTML(open(post_url))
	webmention_link = page.xpath("//link[@rel='webmention']")
	if webmention_link.empty?
		fail NoWebmentionEndpoint
	else 
		begin
			#Should be only one. I guess it's always on a link
			webmention_endpoint = webmention_link[0][:href]
		rescue
			#Something bizarre going on
			fail NoWebmentionEndpoint
		end
	end
end

And lastly, sending the webmention is as easy as:

res = Net::HTTP.post_form(webmention_endpoint, 'source' => post_data["my_post_url"], 'target' => post_data["link"])

Just in case you’ve forgotten: my Jekyll Indieweb repository