rib: Static site generator using Shake

[ bsd3, library, web ] [ Propose Tags ]

Haskell library for writing your own static site generator

[Skip to Readme]


Maintainer's Corner

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,
Change log CHANGELOG.md
Dependencies aeson (>=1.4.2 && <1.5), async (>=2.2.2 && <2.3), base (>=4.7 && <5), binary (>=0.8.6 && <0.9), bytestring (>=0.10.8 && <0.11), clay (>=0.13.1 && <0.14), cmdargs (>=0.10.20 && <0.11), containers (>=0.6.0 && <0.7), data-default (>=0.7.1 && <0.8), fsnotify (>=0.3.0 && <0.4), http-types (>=0.12.3 && <0.13), lens (>=4.17.1 && <4.18), lens-aeson (>=1.0.2 && <1.1), lucid (>=2.9.11 && <2.10), mtl (>=2.2.2 && <2.3), pandoc (>=2.7.3 && <2.8), pandoc-include-code (>=1.4.0 && <1.5), pandoc-types (>=1.17.5 && <1.18), safe (>=0.3.17 && <0.4), shake (>=0.18.3 && <0.19), skylighting (>=0.8.1 && <0.9), text (>=1.2.3 && <1.3), time (>=1.8.0 && <1.9), wai (>=3.2.2 && <3.3), wai-app-static (>=3.1.6 && <3.2), wai-extra (>=3.0.26 && <3.1), warp (>=3.2.28 && <3.3) [details]
License BSD-3-Clause
Copyright 2019 Sridhar Ratnakumar
Author Sridhar Ratnakumar
Maintainer srid@srid.ca
Category Web
Home page https://github.com/srid/rib#readme
Bug tracker https://github.com/srid/rib/issues
Source repo head: git clone https://github.com/srid/rib
Uploaded by sridca at 2019-08-22T00:08:32Z
Distributions NixOS:
Downloads 2350 total (41 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-08-22 [all 1 reports]

Readme for rib-

[back to package description]



BSD3 Hackage

Rib is a Haskell library for writing your own static site generator.

How does it compare to Hakyll?

  • Use the Shake build system
  • Builtin support for using Haskell DSL to define the HTML (Lucid) & CSS (Clay) of your site
    • Like Hakyll, Rib uses Pandoc for parsing the source documents
  • Remain as simple as possible to use (see screenshot below)
  • Optional Nix based workflow for easily reproducible environment

Rib prioritizes the use of existing tools over reinventing them, and enables the user to compose them as they wish instead of having to write code to fit a custom framework.

Here is how your code may look like if you were to generate your static site using Rib:


Getting Started

The easiest way to get started with Rib is to use the template repository, rib-sample, from Github.

Directory structure

Let's look at what's in the template repository:

$ git clone https://github.com/srid/rib-sample.git mysite
$ cd mysite
$ ls -F
a/  b/  default.nix  Main.hs  README.md  rib-sample.cabal

The three key items here are:

  1. Main.hs: Haskell source containing the DSL of the HTML/CSS of your site.
  2. a/: The source content (eg: Markdown sources and static files)
  3. b/: The target directory, initially empty, will contain generated content (i.e., the HTML files, and copied over static content)

The template repository comes with a few sample posts under a/, and a basic HTML layout and CSS style defined in Main.hs.

Run the site

Now let's run them all.

Clone the sample repository locally, install Nix and run your site as follows:

nix-shell --run 'ghcid -T main'

(Note even though the author recommends it Nix is strictly not required; you may simply run ghcid -T main instead of the above command if you do not wish to use Nix.)

Running this command gives you a local HTTP server at http://localhost:8080/ (serving the generated files) that automatically reloads when either the content (a/) or the HTML/CSS/build-actions (Main.hs) changes. Hot reload, in other words.

How Rib works

How does the aforementioned nix-shell command work?

  1. nix-shell will run the given command in a shell environment with all of our dependencies (notably the Haskell ones including the rib library itself) installed.

  2. ghcid will compile your Main.hs and run its main function.

  3. Main.hs:main in turn calls the Shake build action (via Rib.App.run) defined in Rib.Simple.buildAction passing it your function renderPage.

There is quite a bit going on in that step 3! Let's break it down:

  1. Rib.App.run: this parses the CLI arguments and runs the rib CLI "app" which can be run in one of a few modes --- generating static files, watching the a/ directory for changes, starting HTTP server for the b/ directory. By default---without any explicit arguments---this will run the Shake build action passed as argument on every file change and spin up a HTTP server.

  2. Rib.Simple.buildAction: The run function takes a Shake build action to run on file change. Rib.Simple provides a very simple build action for generating the most simple static site --- a list of posts with static assets --- which the sample repository uses.

Run that command, and visit http://localhost:8080 to view your site.

Editing workflow

Now try making some changes to the content, say a/first-post.md. You should see it reflected when you refresh the page. Or change the HTML or CSS of your site in Main.hs; this will trigger ghcid to rebuild the Haskell source and restart the server.

What's next?

Great, by now you should have your static site generator ready and running! What more can you do? Surely you may have specific needs; and this usually translates to running custom Shake actions during the build.

Rib provides helper functions in Rib.Shake and Rib.Pandoc to make this easier. Indeed the Rib.Simple.buildAction function which the sample project readily uses makes use of these functions.

In order to customize your site's build actions,

  1. Copy the source for buildAction from the Rib.Simple module to your Main.hs

  2. Make any customizations you want in your buildAction function. Refer to Hackage for API docs.

  3. Use that as the argument to the Rib.App.run function in your main

Notice how Rib's builtin buildAction is forward-defined which adds to the simplicity of the entire thing.