lua |
Following on from yesterday's post, I decided to try implement proper content negotiation. After a fair amount of time spent getting to grips with [Lua][], I got a [script][] which works very nicely. It implements [server driven][] content negotiation for [media types][mime]. The basic idea of content negotiation is that a resource (e.g., this [graph][])
exists in multiple formats (in this case, [SVG][graph-svg], [PNG][graph-png] and
[GIF][graph-gif]). When a user agent requests the resource, it indicates which
formats it understands by listing them in the (The following description assumes knowledge of the The script works by searching the directory for files with the requested name
but with an additional extension (each of which is a variant). The [media
type][mime] is inferred from the extension using Some browsers include wildcard entries such as To install the [script][], download and save it somewhere (such as
|
|||
URLs shouldn't really contain file extensions (like Doing the same for static files (i.e. files served directly by the webserver)
isn't straightforward because most webservers use the file extension to
determine the MIME type to send in the I decided to try find a solution to this for my webserver of choice,
Lighttpd. Lighttpd has a module which embeds a [Lua][] interpreter and
allows you to write scripts which modify (or even handle) requests. So I wrote
a [script][] which searches the directory for files with the same name as
requested but with an extension. This means that any file can be accessed with
the file extension removed from the URL while still having the correct
The script currently chooses the first matching file, which means that having
multiple files with the same name but different extensions doesn't do anything
useful. The proper method however is to actually do [content negotiation][],
which chooses the format based on the preferences indicated by the HTTP client
in the To use this script, download it and save it somewhere (I use
|
|||
Seeing that I've spent countless hours setting up my Drupal installation, I thought that I would share this with others and document it for future reference. Drupal is an extremely powerful CMS which can be used to create a wide variety of sites. The disadvantage of this is that it requires a fair amount of work to setup a straightforward blog, which involves installing and configuring numerous modules. InstallationSince there is no Ubuntu package for Drupal 6, I created my own package based
on the
Clean URLsClean URLs allows one to have URLs like Lighttpd does however have a module which allows one to add scripts to the
request process written in [Lua][]. A script has already been
[developed][drupal.lua-devel] which implements the required rewriting for Drupal. The following
lines in
BlogWhen Drupal is first installed, there is no mention of blogging as such. The first step is to enable the Blog core module1. This creates a blog content type and enables a blog for each user. (The module is designed for a multi-user blog, but can be used for a single user as well.) However, this doesn't give you all the functionality you expect from a blog engine. Tagging is handled by the Taxonomy core module. You first need to create a vocabulary though, and enable it for blog posts. (This took me ages to discover.) In order to get nice URLs (including the date and post title, for example) you need to install the [Pathauto][] module and configure a pattern for blog posts. You may also want to define a pattern for tags. There is also no archive functionality. The best way that I can find is the
[Views][] module. It includes a pre-defined "archive" view which can display
posts from a specific month, and links to the monthly pages. Even after much
investigation I couldn't get the archive to behave like typical blog archives
(i.e. Other Blog FeaturesThe [Trackback][] and [Pingback][] modules implement automatic linking with other blogs. (I haven't actually tested these yet.) The Blog API core module allows the blog to be managed with external clients. The [Markdown][markdown-mod] module allows you to write posts using [Markdown][] syntax instead of HTML. CommentsDrupal enables comments for blog posts by default. The [Akismet][akismet-mod] module implements spam filtering using the [Akismet][] service. The [CAPTCHA][captcha-mod] and [reCAPTCHA][recaptcha-mod] modules allows you to require users to answer a [reCAPTCHA][] when submitting comments. (I haven't actually enabled [CAPTCHAs][captcha] since I haven't gotten any comment spam yet. Or real comments for that matter...) Posting by emailThe [Mailhandler][] module allows you to submit posts via email. The configuration is fairly straightforward, except for the available commands which can be found [here][commands]. These can be specified at the beginning of emails and in the configuration as defaults. I use the following commands.
This creates blog posts and tags them with the "mail" tag. Posts are published and promoted to the front page, and comments are enabled. The one thing it doesn't handle is attachments (such as images). There are a couple of modules2 which support this, but they aren't available for Drupal 6 yet. ([Vhata][] has also hacked together a [photo blogging][phoblog] system, but this isn't implemented as a Drupal module.) I don't really need this feature, so I'm going to wait until these modules are updated. OpenIDThe [OpenID][openid-mod] module allows you to log into your site using [OpenID][]. The [OpenID URL][openidurl] module allows you to delegate your Drupal site as an OpenID by specifying your provider and/or your [Yadis][] document. Yadis AdvertisementYadis documents are advertised with a The former method can be accomplished with the
The following lines in
Random StuffThe tag block is generated by the [Tagadelic][] module. The "Recent Tracks" block is generated from my [LastFM][] feed by the Aggregator core module, and the list of networks is simply a custom block. The [Atom][] feed is generated by the [Atom][atom-mod] module. The contact form, search and file upload are all core modules. Missing StuffThe one thing I haven't sorted out is image handling. There are a couple ways to [handle images][drupal-images] in Drupal, but none of these appeal to me (they're too complicated). I will probably just upload images as attachments and insert them manually in the body. |
|||
