Myself, Coding, Ranting, and Madness

The Consciousness Stream Continues…

Google Currents

8 Aug 2012 8:00 Tags: None

Google have launched another one of their shiny services — Currents — which, at first glance seems little more that a producer side RSS aggregator, optimised for Phone and tablets. In fact, as far as I can tell, it is little more than that. But, I suspect that Google are planning to go somewhere slightly more with this.

Google Currents QR Code

Firstly, for those of you who have such fun devices, and are interested in using Google Currents, you can add my blog at one of google's less compact links.

With the important marketing out-of-the-way, what follows is my perceptions and experience of Google Currents and it getting it to work with WordPress.

The producer side allows users to create their 'editions'1. An edition the contains one or more sections, which are intended to be based off of other feeds — RSS, YouTube videos, Twitter, and others — which then generates the content. As the content is pulled from feeds, the original layout and styles are not preserved, except when embedded directly in the contents, allowing the pages to be laid out in a way that is likely to suit the target device.

There are, however, currently some teething issues. The most complex source to get data from is, probably, the RSS feed. Three options for how to treat the feed. The first is to take the content of each feed item to be the post in its entirety, which is the most likely to create neat results. This can be augmented, in a second option, to follow the item's link and scan for additional media, such as images and videos, that are marked as attachments to the post.

The third option is to ignore the item's content all together and generate the entry from the original post. This, however, requires a bit of luck to work properly, as the original post is likely to be surrounded by title bars, navigation menus, and other paraphernalia. Thus, Google's bot has to work out what is post and what isn't

For this reason, my initial set-up attempts ran into issues of not displaying images and other related data correctly, if at all. The way to go clearly seemed to be using the feed mode, but I prefer having the public feed show only excerpts of the post2. The idea then was to have a separate feed that led to Google Currents, something that I'm still working on, as it seems to require rebuilding part of WordPress's internals

Switching over to full posts being taken from the feed made things look a lot better, with images showing up clearly. Some style work on the producer side help enormously too: footnotes made to look like footnotes, and better handling of citations of small screens, where the browser was struggling to wrap the long links in a pleasing way3.

One problem, however, persisted. Something was trying to be clever and do link-rewriting to make sure that all relative links were pointer to the correct pages. However, it was classifying fragment links as a form of relative link. Fragment links, which just point to a particular element on the page, are the basis of the footnote system, and this transform not only caused the footnote links to not work on the page, but to have them point at meaningless items on the home page of the blog.

This turned out, in the end, to be an easy fix. The source of the problem was the RSS generation system in use by WordPress, which performed the link sanitization. The code correctly broke down the URI into its components, then analysed those to determine the correct absolute link. All that I needed to do was add a final else statement towards the end of the logic. By this point, it had determined that the relative URI had no path or query components, and was non-empty, meaning that it consisted only of a fragment. In this case, the relative link should be returned unchanged.

The patch is shown below, in case anyone else ever needs to try to stop WordPress from re-writing fragment links.

diff --git a/wp-includes/class-simplepie.php b/wp-includes/class-simplepie.php index ef91f58..a8d84da 100644 --- a/wp-includes/class-simplepie.php +++ b/wp-includes/class-simplepie.php @@ -11823,6 +11823,11 @@ class SimplePie_IRI { $target->set_query($base->get_query()); } + else + { + // Just a single fragment is permitted + $target = $relative; + } } } $target->set_fragment($relative->get_fragment());

In the end, this didn't actually fix the problem. Something upstream then rewrote the links (also incorrectly). I threw together a bit of JavaScript to attempt to solve the problem dynamically; it works in the preview, but that is running in Chrome, the behaviours of which I am well aware of. How phones and tablets are going to take it is something of a different matter. In the mean time, the full posts in the RSS feeds may now have proper linking in some feed readers4.

  1. 1 The use of this work confuses me. What Google are calling an 'edition' is what I would call a 'publication' — it contains all the back items
  2. 2 Mainly due to formatting issues with the footnotes and other problems
  3. 3 They will now take up one line, and any overflow will be replaced with an ellipsis
  4. 4 unfortunately, Google Reader also seems to do some form of link rewriting