Roller tips and tricks : image and Planet
By Frederic Pariente on Mar 13, 2009
Apache Roller is the blog-roll application that currently powers the blogs.sun.com site. It comes with a large selection of templates that allows anyone, with no particular programming skills, to easily get started with blogging. To further customize your blog though, you will need to switch to manual and learn some HTML, CSS and Velocity, Roller's template programming language.
I get quite often asked about how to program some of the features that you see on this blog. Simple things but they seem to be of enough global interest, so I'm finally blogging about them here. I'm planning an initial series of 3-4 posts on the top questions that I got so far. There will be more posts of tips & tricks as I get more requests. And always feel free to ask right here, in the Comments section.
How to get images to display in an RSS reader, for sure?
If you upload an image into your blog's resource directory and use it as part of a blog post, Roller will by default strip out the hostname out of the URL. E.g. if you type
<img src="http://blogs.sun.com/openomics/resource/happy2009.png" />, Roller will save
<img src="/openomics/resource/happy2009.png" />. I.e. it will convert an absolute URL to a relative URL --relative to your blog website's root URL-- if the image sits on the same website. And there's apparently nothing you can do about it --I tried at least and I could not find a checkbox anywhere in the blogger's admin interface to prevent this to happen.
This behavior of course causes no problem to your online visitors. They are surfing your blog's website --here blogs.sun.com-- and the relative URL gets resolved fine by the browser. Your subscribers though, that are reading your blog offline, may run into issues. If they are a direct subscriber of your own feed, they are typically fine. If they however read you through a subscription to an aggregation of feeds --in my case e.g., the ISV Engineering Planet on planets.sun.com-- the RSS Reader is not able to track back to the location of the image (
http://blogs.sun.com/openomics/resource/happy2009.png) from the relative URL (
/openomics/resource/happy2009.png). I am guessing that, at best, it (wrongly) resolves it as
http://planets.sun.com/openomics/resource/happy2009.png and you get a broken link as shown below --the question mark.
Luckily there is one workaround. Most servers have multiple hostnames. The original hostname is often referred to as the nodename and the others as aliases. It is e.g. a common practice to have a server running a given service --say, IMAP email-- also respond to the name of service.domain.com --in this case, imap.domain.com. It is also a common practice to give an alias to a server if it helps not to generate an error on frequent typos. Is it blogs.sun.com or blog.sun.com? Well, guess what? It is both. Sun IT knew we would not remember which one so both hostnames point to the same server. From the point of view of Apache Roller though, it is running on blogs.sun.com, full stop. The work around is thus to refer to your image as follows :
<img src="http://blog.sun.com/openomics/resource/happy2009.png" /> --blog without an s. Roller will not recognize the name of the server it is running on and will thus not strip out the hostname. The full URL will be passed on and the image will never be a broken link, no matter where one is reading the post from.