Hooks

Hooks are a way to plug extra features (called actions) to VictorPy 0.1.32 at some pre-defined points. Common hooks use cases are: copying files, transpiling [some language] to JS/CSS/whatever, pinging some external service…

VictorPy 0.1.32 includes the fallowing hooks:

  • after_render: when the pages rendering process is completed.
  • affet_build: when the site building process is completed.

Configuring hooks

Configuring hook is generally two steps process:

  1. Linking an action to a hook (i.e. when to do what…).
  2. Configuring each action.

For example, if you want to transpile your Less files to CSS each time your site has been rendered, you will have to say that you want to trigger the Less to CSS transpiling process after rendering and to tell VictorPy 0.1.32 where your Less source files are located andwhere you want to create the CSS files.

Linking actions to hooks is done using the hooks config parameter:

hooks:
    after_render:              # the hook
        - compile_less_files   # the action to launch
        # ...

Processing order – The actions list is ordered: actions on top will be processed first.

Action related configuration should be done in a dedicated config parameters (every action defines its own configuration structure). For example:

less:
    files:
        - 'app/less/main.less': "static/css/main.min.css"

Built-in actions

VictorPy 0.1.32 ships with a set of predefined actions:

compile_less_files

Less is a CSS pre-processor. The compile_less_files takes your Less files and transpile it into plain CSS files.

config.yaml

hooks:
    after_render:
        - copy_files(front)

less:
    files:
        - 'app/less/regular.less': "static/css/regular.css"
        - 'app/less/home.less': "static/css/home.css"
        - 'app/less/other.less': "static/css/other.css"

copy_files

This action allow you to collect static files (inspired by the Django collectstatic command).

config.yaml

hooks:
    after_render:
        - copy_files(front)
        - copy_files(static)

copy_files:
    front:
        'app/__javascript__/main.js': "static/js/main.js"
        'app/__javascript__/other.js': "static/js/other.js"
    static:
        '/toto': 'tata'

minify_html

Delete spaces in HTML files. Operates on files located in build_path.

config.yaml

hooks:
    after_build:
        - minify_html

create_lunr_index

This hook creates an index file for using with the Lunr search engine.

config.yaml

hooks:
    after_render:
        - create_lunr_index

User-defined hooks

To be documented.