Dear Lazyweb

Some of you customise your journal’s appearance using LiveJournal’s S2 system. The whole thing looks a bit baroque, with much mentioning of “layers”, so I thought I’d just ask questions of people who might know how to do what I want.

I have a thingy which generates an Atom feed from the comments on each of public postings (by “thingy” I mean a couple of Python scripts, one of which is a heavily modified version of ljdump and the other of which is a script which generates the feeds using the dumped information. I might publish them if anyone’s interested). Proper blogs have these feeds, so I thought mine should too.

I would like to make people’s browsers aware of the feed when viewing an entry, which means sticking some extra <link> elements into the <head> element of the entry view. I’d also like to link to the feed somewhere on the entry page, probably in the little list of stuff you can do with the entry (you know, permalink, write a comment, add to memories, denounce, and so on). The link would reference http://www.noctua.org.uk/paul/lj/feeds/nnnn.xml, where nnnn is the unique number which LJ puts in the permalink to the entry itself (for example, this entry‘s number is 83644).

At some stage the script is also going to produce a single feed of all comments on my public postings (and maybe all my comments on your public postings, if you don’t object). So I’d also like to know how to stick stuff in the <head> of the entire journal view (which already links to the Atom feed of my postings which LJ generates itself).

Any help you can give in telling me where to start with this stuff would be much appreciated.

3 Comments on "Dear Lazyweb"


  1. OK, the actual process of getting to a point where you can even get into the code is far more of a pain than it should be. This tutorial is probably a starting point.

    To put extra links in the <head> you want to create a function called function Page::print_custom_head(). Once you have a theme layer open in the layer editor, you can just define the function there. After that the syntax is {"""<a href="">""";}. You can’t put any scripting language there, but if it’s just a link to a page generated by your Python somewhere else, that should be fine. You don’t have to rewrite the whole <head> section, just include any additional lines you want to go in there and let the layout layer handle the rest of it.

    Adding links to the linkbar is possible, but as a non-programmer I find it quite difficult. Essentially LJ’s code generates the linkbar by iterating over some keys, and the code that actually determines what happens is hidden somewhere, it’s not an explicit part of the public layers. You’re using one of the user-created styles, which is frankly a lot better written than the LJ originating ones, so you might have a chance.

    The relevant bits you need to modify are function EntryLite::print_linkbar() and function Entry::print_linkbar() (search within layout code for the default version). If you use that in your theme layer, you can over-write that default version. S2 is mostly Perl, so I’m hoping you’ll be able to read the code in order to decide what to do with it. Other bit of information you need is a variable to generate the entry number on its own (as opposed to generating the entry link); I think $e.itemid will work.

    This is muddled because I have absolutely no programming knowledge, which makes it hard to explain the stuff I’ve picked up about S2. I’m sorry if I’ve spelled out things which are completely obvious to a programmer, and even more so if I’ve left out critical information, but hopefully that can be remedied if you ask what you need to know.

    Reply

    1. So it turns out that the right thing is to create a theme layer which defines EntryPage::print_custom_head. That way I don’t also get my Atom discovery turning up on all the other children of Page, like the day view and so on. An EntryPage has an entry (which is an Entry), which has an itemid, which is the thing I want. If I also only want the links to turn up on public entries, I end up with this.

      There was a moment of confusion when I lost all my previous journal customisations from the wizard (I made the fonts slightly bigger and so on) when I selected my new theme, but I went into the style editor and told it that my style should use the custom theme layer and the old user layer generated by the wizard. That fixed it.

      Next the linkbar stuff, which looks a bit harder.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *