Static - Static Site Generator

Static is a simple static site generator written in Clojure. For a sample site build using static see

1 Features

Static can parse org-mode and markdown files.

2 Dependencies

Static requires the leiningen build tool. Once installed, you can build Static with the following commands from within the project directory structure:

$ lein deps
$ lein uberjar

3 Usage

Creating a static site usually involves the following,

  • Set up the basic structure of the site
  • Create some posts
  • Run your site locally to see how it looks
  • Deploy your site

A basic static site usually looks something like this:

|-- config.clj
`-- resources
   |-- posts
   |   |-- 2009-04-17-back-up-and-restore-a-mysql-database.markdown
   |   |-- 2010-02-10-a-simple-clojure-irc-client.markdown
   |   `-- 2010-08-02-using-clojure-contrib-generic-interfaces.markdown
   |-- public
   |   `-- 404.html
   |-- site
   |   `-- index.markdown
   `-- templates
       `-- default.clj

An overview of what each of these does:

3.1 config.clj

Contains a vector of configuration options.

  • :site-title - Title of the site.
  • :site-description - Description of the site.
  • :site-url - URL of the site.
  • :author-name - Name of the author.
  • :author-email - E-mail address of the author.
  • :copyright-year - Year the pages were created/copyrighted.
  • :in-dir - Directory containing site content by default resources/
  • :out-dir - Directory to save compiled files.
  • :atomic-build - When set, will build the site on a temporary directory first then move that directory to :out-dir.
  • :default-template - Default template to use.
  • :encoding - Encoding to use for read write operations.
  • :posts-per-page - Number of posts in latest post pages.
  • :blog-as-index - If true use blog as index.
  • :emacs - path to emacs if you want to render .org files.
  • :emacs-eval - elisp code to be evaluated on the emacs process.
  • :host - remote host to deploy to.
  • :user - remote username
  • :deploy-dir - Remote directory to deploy to.
  • :rsync - path to rsync if you want to deploy with rsync.

The variables can later be reused (for example in your default template) as:

(:author-name (static.config/config))

3.2 posts/

Folder containing posts, the format of these files are important, as named as YEAR-MONTH-DATE-title.MARKDOWN.

3.3 public/

Folder containing static data such as images, css, javascript etc. Folder structure will be mirrored exactly.

3.4 site/

Folder containing pages that are not posts.

3.5 templates/

Folder containing templates that are used to render posts and pages with.

4 Markup

Supported markup languages,

  • markdown
  • org-mode (via emacs)
  • clojure (hiccup)
  • cssgen
  • html

4.1 Setting per page/post settings

Setting the template, title etc, for a page/post is done using a header placed at the top of the file,

4.1.1 org-mode

#+title: Blogging Like a Hacker
#+tags: clojure

4.1.2 Markdown

template: temp-en.clj
title: Blogging Like a Hacker

4.1.3 Clojure

{:title "Blogging Like a Hacker"}

4.1.4 cssgen

cssgen does not support file-specific settings.

4.2 Page/Post Settings

  • template - If set, this specifies the template file to use. Use the layout file name with file extension. Layout files must be placed in the templates directory.
  • title - Override the use of default title.
  • alias - Generates redirect pages for posts with aliases set. (["/first-alias/index.html", "/second-alias/index.html"]) Place the full path of the alias (place to redirect from) inside the destination post.

Any other setting you provide can be accessed from within your template.

5 Installation

You need to place the uberjar lein created to the folder containing config.clj.

5.1 Building the site

java -jar static-app.jar --build

5.2 Testing the site

You can test the site locally using jetty, which will launch on http://localhost:8080. The site will rebuild if you change any of the source files.

java -jar static-app.jar --watch

In order to run just jetty,

java -jar static-app.jar --jetty

5.3 Deploying the site

5.3.1 RSYNC

$ java -jar static-app.jar --rsync

6 Code

You can grab the latest version from the repo.

For bug reports/fixes/help, see contact.

Any feature requests are also welcome see contact.

7 License

Copyright (C) 2010, 2011, 2012

Distributed under the Eclipse Public License, the same as Clojure.