Christian Koch


Code/Molokai

Molokai is a minimal wiki-like web application for Lua, bozohttpd and NetBSD. I would build a website about Molokai using Molokai, but unfortunately, I don't have access to a host running NetBSD that is also connected to the public internet. (The server hosting this website is running Linux.) I've copied the information I've already written about Molokai here.

Molokai is a minimal wiki-like web application for NetBSD. It is written in Lua against Cadet, an equally minimal interface between Lua and bozohttpd, NetBSD's default HTTP daemon. Furthermore, it's licensed under a BSD-style license.

Molokai's Features

Installing Molokai

You need a fairly recent version of bozohttpd — specifically, one with Lua scripting support built-in. If your httpd(8) recognizes the "-L" option, then you're good to go. The most recent releases of NetBSD should be okay.

bozohttpd was designed to be run from inetd(8), so we recommend enabling it in rc.conf(5).

You need to add an entry to inetd.conf(5), something like this:

    http  stream  tcp nowait:600  _httpd  /usr/libexec/httpd  \
      httpd -L PREFIX /path/to/molokai.lua /path/to/slashdir

where PREFIX can be anything, but preferably it is some sort of title for your website, since it will show up as part of the URL.

The slashdir is where static content goes — stylesheets, photos, etc. This should point to the public/ directory.

Using Molokai

A Molokai installation has a simple directory structure. It is flexible, but the defaults should be sensible enough:

pages/
    index.html
public/
    css/
        molokai.css
cadet.lua
molokai.lua
template.html

The template.html contains the HTML common to all pages. It contains the doctype, the root <html>, <head> and <body> elements, and the variable {{content}}, which is replaced by the requested page's content.

The default template looks something like this:

<!doctype html>

<html lang="en">
<head>
  <meta charset="iso8859-1"/>
  <title>Molokai</title>
  <link rel="stylesheet" type="text/css" href="/css/molokai.css"/>
</head>
<body>

<header>
  <h1>Molokai</h1>
  <hr/>
</header>

{{content}}

<footer>
  <hr/>
  <p>Little blurb at the end</p>
</footer>

</body>
</html>

Writing articles

To create a new article, write a new file in the pages/ directory. Currently (1/12/14), Molokai supports only one markup language: plain vanilla HTML. You can access the page pages/wxyz.html with the URL ?page=wxyz.

You can use the file system to create hierarchies of articles. For example, the page pages/foo/bar/baz/wxyz.html can be accessed with the url ?page=foo/bar/baz/wxyz.

Every Molokai installation should at least have a page called "index.html". Molokai will default to this if a client doesn't explicitly request any page.

Using the public/ dir

Static assets (stylesheets, images, etc.) go in the public/ directory. This should be the same directory as the "slashdir" configured in inetd.conf(5). The public/ directory serves as bozohttpd's root, therefore, you can access public/css/style.css from the URL http://localhost/css/style.css.

If you want the static assets to be more easily navigable, try passing the "-X" option to bozohttpd.

Tips and tricks

Use pre-compiled Lua bytecode

For a little performance boost, we recommend compiling cadet.lua and molokai.lua to Lua bytecode with luac(1). bozohttpd will happily interpret these just like any other Lua source.

Working around the templating language

" and " are reserved for the templating language. If your content actually contains the " and/or " patterns, then you might need to circumvent it:

TODO

Even though Molokai is tiny, it's still far from complete.


Download