grubby: static site generator for git repos written in Ruby

Source: git.btxx.org
18 points by bt a day ago on lobsters | 11 comments

Static site generator for Git repos written in Ruby.

Forked and heavily inspired by RepoRat

Requirements

  • Git
  • Ruby 3.0+
  • Kramdown

Configuration

Grubby is fairly opinionated out of the box. It’s meant to be used as-is without much need for tinkering. Kramdown is the default Markdown parser, which you are free to swap out but I can’t guarantee things will be bug-free! It is also assumed that all of your bare git repos end with the .git extension. The core repo index generation will not working properly without this!

All you should ever touch is the _config.yml file for setting your core domain and paths.

If you wish to change the CSS, navigation links or footer content, then edit the style.css, _header.html, and _footer.html accordingly. Feel free to experiment!

By default the core “repo index” is created at the root of the main directory and is named index.html. You can change this file output name inside the _config.yml as well.

Usage

This guide assumes you are using a form of “shared hosting” (in this case NearlyFreeSpeech.NET). Although running things on your own VPS will be very similar.

Below is based on your bare git repos being under /home/public/git.sitename.org.

  1. Clone this project into your private directory (ie. /home/private/)
  2. Now navigate to a repo inside /home/public (ie. cd coolrepo.git)
  3. Create a new file under hooks: touch /hooks/post-update
  4. Give that file proper permissions: chmod +x /hooks/post-update
  5. Add the following code to that file:
#!/bin/sh

unset GIT_DIR

# Needed for cloning over plain HTTP
git update-server-info

# Rebuild the static site from a temporary checkout
repo_name=$(basename "$PWD" .git)
temporary_dir=$(mktemp -d)

git clone --quiet "$PWD" "$temporary_dir/$repo_name"
cp "$PWD/description" "$temporary_dir/$repo_name/.git/description"
(cd "$temporary_dir/$repo_name" && ruby /home/private/grubby/grubby.rb)

rm -rf "$temporary_dir"

Now you can take it for a test drive! Simply run:

./hooks/post-update

Your individual repo website will be generated at /home/public/git.sitename.org/coolrepo, along with an updated repo index (index.html by default) at the root /home/public/git.sitename.org/.

You can expand on this by instead using this call inside your hooks/post-receive file or even using a global post-update to avoid including this for each project.

Caveats

  • Does not create pages for individual commit changes, branches, etc.