sitefs

sitefs will be a filesystem for Plan 9 for simple file-based content management for web sites. The underlying files can be edited like editing a wiki page, but will be represented by sitefs as read-only files with a header and footer added. Any web server that serves files can serve dynamic pages created this way.

The point is to support the dumbest web server imaginable – one that only knows how to read files from disk and serve them. Dynamic content (scripts) can be created by setting a file's executable bit; it will be run when the file is requested and its output will be used as the body of the page, but the header and footer are still added.

This project is a dream right now, but I'd like to make it happen soon. There have been at least two attempts at similar projects, as according to fgb it is an "old idea." But his has not been released and the other that I know of (by mht) is not production-ready and seems to have a grander scope than I imagine for sitefs.

I'm new to synthetic file servers and Plan 9, but I think I can make it work.

Rough Workings

For my explanations, I will assume a directory layout like this.

/pub/
Where sitefs is bound.
/src/
Source files for the site. These are the page bodies, or scripts which generate page bodies.
/tpl/
Files like header and footer

The web server should be directed to serve files from /pub/, where sitefs will be mounted. There will probably be other files or directories here to be served raw, like images and stylesheets.

Files in /src/ will be mirrored in /pub/ as they are save for the exception that their contents will have /tpl/header prepended and /tpl/footer appended. This will happen at every read with slight overhead (three additional files are opened instead of one), but the web server and OS are free to cache according to their ways.

Files which are executable can be served as though their output were the page body. Scripts which need to send their own headers (ex: for redirecting) can be put in /pub/ directly so as to not be filtered by sitefs.

Extensions

How far can I go with this? Can I take it as far as having templates and partials as in Rails? It is possible, although I doubt that I could do all that and retain its simplicity.

One thing I can already see myself wanting is per-file header/footer specification. My front page may need a different header than every other page, for example. But this can be done by having two instances of sitefs bound to the same /pub/ directory. One is configured to mirror a directory with the front page and a directory with the templates for that page, and the other with every other page.

I think that files should be able to have a section in their header which will not appear when they are exported with sitefs but can be used by scripts as metadata. It may look something like this:

META
This text will not be output.
Nor will this
END
This is where output begins.

I think that header and footer should be able to be scripts as well.


Comments

Click here to view the comments on this post.