Webmention.io

Webmention.io is a hosted service created to easily handle webmentions (and legacy pingbacks) on any web page. Currently it is not open for signups, but you can download the source code and run it on your own server.

You might also be interested in reading about this project on the IndieWebCamp wiki.

Use it on your site

Once you have a username, add the following tags to your HTML:

    <link rel="pingback" href="http://webmention.io/username/xmlrpc" />
    <link rel="webmention" href="http://webmention.io/username/webmention" />

The system will begin collecting webmentions and pingbacks on your behalf.

Forward pingbacks to webmentions

If you want to accept pingbacks but don't want to deal with the hassle of XMLRPC, you can use this service to forward pingbacks as webmentions to your server. You don't need an account for this to work.

<link rel="pingback" href="http://webmention.io/webmention?forward=http://example.com/endpoint" />

For further details and an example, please refer to the README.

Display a mention counter

You can use the API from Javascript to display a mention count of one or more URLs

Getting the data manually

To retrieve the data manually using jQuery, you can make a request like the following. Be sure to add a parameter for your access token if your account is set to disable public access to the data.

$(function(){
  $.getJSON("http://webmention.io/api/count?jsonp=?", {
    target: "http://example.com/page/100"
  }, function(data){
    console.log(data.count);
  });
});

Displaying counts automatically

You can include some simple markup and a Javascript file to automatically display the mention counter for one or more URLs on a page.

First, choose an element that will be used to display the counter. Add the an attribute data-webmention-count to it, as well as data-url="" with the full URL of the page you would like to count. This might look something like the following:

<span data-indieweb-comment-count data-url="http://example.com/page/100"></span> mentions

Then, add the following script tag to your page after you've included jQuery:

<script type="text/javascript" src="http://webmention.io/js/mentions.js"></script>

Show all mentions

You can also use the API to show all mentions of a URL. This will work with jQuery or you can use the API directly from a server.

$(function(){
  $.getJSON("http://webmention.io/api/mentions?jsonp=?", {
    target: "http://example.com/page/100"
  }, function(data){
    console.log(data);
  });
});

Which will return data in this format:

{
  "links": [
    {
      "source": "http://tantek.com/2013/112/t2/milestone-show-indieweb-comments-h-entry-pingback",
      "verified": true,
      "verified_date": "2013-04-25T17:09:33-07:00",
      "id": 900,
      "data": {
        "author": {
          "name": "Tantek Çelik",
          "url": "http://tantek.com/",
          "photo": "http://tantek.com/logo.jpg"
        },
        "name": "Another milestone: @eschnou automatically shows #indieweb comments with h-entry sent via pingback http://eschnou.com/entry/testing-indieweb-federation-with-waterpigscouk-aaronpareckicom-and--62-24908.html",
        "content": "Another milestone: <a class=\"auto-link h-x-username\" href=\"https:\/\/twitter.com\/eschnou\">@eschnou<\/a> automatically shows #indieweb comments with h-entry sent via pingback <a class=\"auto-link\" href=\"http:\/\/eschnou.com\/entry\/testing-indieweb-federation-with-waterpigscouk-aaronpareckicom-and--62-24908.html\">http:\/\/eschnou.com\/entry\/testing-indieweb-federation-with-waterpigscouk-aaronpareckicom-and--62-24908.html<\/a>",
        "published": "2013-04-22T15:03:00-07:00",
        "published_ts": 1366668180,
        "url": "http://tantek.com/2013/112/t2/milestone-show-indieweb-comments-h-entry-pingback"
      }
    }
  ]
}

Streaming API

You can use the Websockets API to receive comments on specific URLs in realtime!

Below is sample code for connecting to the Websockets API and rendering inline comments in real time on a specific post.

<script>
var commentContainerSelector = '#comments ul';
 
if($(commentContainerSelector).length > 0 && "WebSocket" in window) {
  var ws = new WebSocket("ws://webmention.io:8080");
  ws.onopen = function(event) {
    // Send the current window URL to the server to register to receive notifications about this URL
    ws.send(window.location);
  };
  ws.onmessage = function(event) {
    var data = JSON.parse(event.data);

    if(data && data.type == "webmention") {
      // Create a simple <li> element with the information from the post.
      // Probably you will want to change the HTML generated here.
      var comment = $('<li/>').html('<a href="'+data.author.url+'"><img src="'+data.author.photo+'" width="48"></a> <a href="'+data.author.url+'">'+data.author.name+'</a><br />'+data.content+'<br /><a href="'+data.url+'">'+data.published+'</a>');

      // Check if we've already added a comment for this ID, and update the existing one if so
      if($("#"+data.element_id).length == 0) {
        $(commentContainerSelector).append(comment);
      } else {
        $("#"+data.element_id+" li").html(comment);
      }
    }
  };
}
</script>

More Information

You can read more information in the project's README file.