jason-dour / hugo-preproc

Helper for Hugo to provide for pre-processing of files.
GNU Affero General Public License v3.0
10 stars 0 forks source link
go golang golang-cobra golang-viper hugo hugo-preproc static-site static-site-generator

hugo-preproc

Helper for Hugo to provide for pre-processing of files.

Purpose

Provide for a flexible pre-processor for Hugo, since we cannot as a community appear to be able to get certain filetypes supported for external handlers/processors in the core Hugo code.

Intended to assist with any sort of pre-processing desired for publishing files, such as:

Use

A configuration file is used to define processing. By default, the config filename is .hugo-preproc.yaml (or .toml, or .json).

You can specify a config file on command line with the -c/--config option.

Execute the command and processing occurs based on the configuration.

Configuration Syntax

The file has two primary keys: git and processors, such as this example:

git:
  - path: path/to/repo
    processors:
      - mode: head | each | all
        file: path/to/output/{{ .Commit.Hash }}
        template: Entry {{ .<field> }}
exec:
  - path: path/to/top/directory
    pattern: "*.md"
    command: echo {{ . }}

The git key is an array object, with each array element defined as follows:

The exec key is an array object, with each array element defined as follows:

The array entries will be executed serially, in the order in which they are defined.

Configuration Data Structure

Go Templates

We are using Go Templates to process the file and template keys in each git handler, as well as the command key in each processors object.

Other than standard Go Template functions, we also add:

Additionally, we've now mapped the full library of Masterminds/sprig template functions. For 1.x releases of hugo-preproc we will leave our custom template functions in place. When we move to 2.x releases, we will deprecate the above custom functions in favor of sprig.

Go Template Input

We provide the following input for the configured handlers.