Automating tasks using hooks

Most websites need more than just HTML pages, and chances are that you’ll be using a few more tools than just Tiberius. You may want to generate stylesheets using less or sass, for example. And when your website is ready for the world to see, those generated files will have to get to the correct place on your webserver.

Tiberius Hooks provide an easy way to execute these custom scripts and commands during builds.

Hook timeline

  1. Tiberius reads the configuration file
  2. Project directory structure sanity check
  3. Execute PreBuild hooks
  4. Load templates and content files
  5. Generate pages
  6. Execute PostBuild hooks
  7. In case of publish: execute Publish hooks

Configuring hooks

Hooks are defined in the main tiberius.cfg configuration file:

Name = "A name that describes your hook, for logging"
Command = "echo"
Args = ["arg1", "arg2"]
Silent = false
Draft = false

The Name and Command parameters are required.

Hooks with Draft set to true will only be run in draft mode. Remember that the built-in development server always forces Tiberius to run in draft.

If you need multiple hooks, simply repeat the block. Hooks of the same type will be run in the order they appear in the configuration file.

Environment variables

Scripts run as hooks have access to a few extra environment variables:

These contain the absolute path to important project directories.