My Blog Has RSS
From time to time, sharing articles on my website with people, I have been asked, has my website no RSS feed? I'm flattered that anybody would care to stay informed of my occasional postings, but no, I hadn't gotten around to it. Then yesterday the topic came up again and it finally seemed like a worthwhile distraction for an evening of programming.
Adding an RSS feed to an awful
website is straightforward. You add a
define-page form like this:
(define-page "/rss" (lambda _ (awful-response-headers '((content-type application/rss+xml))) `((literal "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>") (rss ...))) no-template: #t)
I have given a simple
_ as the formal parameter(s) of the page handler
as a way of showing that I don't care how many or what arguments this
procedure is called with. The keyword
no-template: #t tells awful that
the page handler is going to provide the entire document, as opposed to
just to body of an HTML document.
awful-response-headers call establishes the content-type that we
will be serving, which is application/rss+xml. Then we just return an
SXML structure, and awful will convert this to XML and serve it.
The first form of the structure that gives
literal ... is the only way I
know of so far to include the XML version and encoding header verbatim.
It would be nicer to give that as a form like
(?xml (@ (version "1.0")
...)), and maybe I'll root around with the translation rules later on to
make that work. For now, we can just use
After that comes the rss root element, contents of which I have ellided.
Multiple Feeds and HTTP Errors
Although in reality there is only one section of my website with dated
articles appropriate for an RSS feed, I wanted to leave open the
possibility of having multiple feeds for hypothetical subsections of the
site. These feeds could be requested with urls like
an invalid path is passed for p, then an appropriate HTTP error should be
Quickly I'll just say that to get the value of a query variable in awful, you use a form like:
Issuing HTTP errors was something that I did not previously know how to
do, so I looked into that and found that it's quite simple. Note that
when you send an HTTP error, the error message is sent as an HTML
document, so you just need to arrange your code so that you don't change
the content-type to application/rss+xml until after you know that the
request was valid. To send an HTTP error from an awful app, call the
send-status, provided by the
spiffy egg (got to love these
names), with a valid status-code symbol. The list of valid status-code
symbols is not in spiffy, but in
intarweb. You can give a
message in an optional second argument. The error for an invalid path
request in my RSS handler is an HTTP 400 code, and it looks like this:
(send-status 'bad-request (sprintf "No RSS channel for path ~S" path))
The rest of building an RSS feed in awful is all just basic sxml stuff. Look up the RSS format and make an sxml document in that format. No need to go over all that here.
Room for Improvement
Now that I have a basic RSS feed on my site, there are a couple of obvious directions to go for improvement. One is to add an Atom feed, as well. Another is automatic descriptions. My RSS feed does not have descriptions for most of the entries because under the current system, I have to manually add description metadata to each entry, a practice that I have only now begun. It would be nice if, lacking description metadata, the first couple of sentences could be pulled from the entry as a substitute. Another improvement would be in providing a way for visitors to subscribe only to certain tags or keywords. Some visitors might only want to know about Mowedline, some about Solaronite, or likewise for any of the other topics that I sporadically blog about.
Well, Solaronite improves and you can now stay informed of blog updates on this site more conveniently than before. Onward and upward. Arriba y arriba.