Filters
Filters let another program process the text inside them. You could, for example, write Sass or SCSS in your template and use a filter to compile it to regular CSS to be included when the template is rendered.
Filters are implemented through commands just as you would run them in a terminal. The content of the filter is given to the command through stdin and it's unescaped stdout is put in the template.
Filters are processed during compile time. Hence, you cannot use interpolation in them and you won't need to escape any #
.
You can also give space-separated arguments to the command. Just like in the shell, you may enclose arguments in strings which will be parsed like regular Go strings using strconv.Unquote
.
Executing arbitrary commands poses a security risk (Imagine someone used rm -rf --no-preserve-root /
as a filter).
While you should of course always vet what go generate
executes, it is always better to be safe than sorry. Hence, corgi will only run filters previously approved.
You can approve a filter by specifying it in the -trusted-filter
flag.
On Linux, macOS, and Windows, you can also use corgi -edit-trusted-filters
to start an editor to edit a list of user-wide trusted filters, or directly open $HOME/.config/corgi/trusted_filters
or %AppData%\Local\corgi\trusted_filters
.
If you trust the template you are running (or just don't care if someone steals your bank details ;)), you can set the -trust-all-filters
flag to i know this is dangerous
to allow all filters to be run.
The Built-In Raw Filter
If you don't specify any command, corgi will write the contents verbatim to the document. This is useful, if you want to include an HTML snippet like an svg, without the hassle of converting it to corgi-syntax.
It is equivalent to using :tee
, except that it doesn't require tee
to be installed on the system.
You don't need to approve the raw filter, it is always available.
Minification
The Raw Filter can also minify HTML, SVGs, JavaScript, and CSS. Simply write html
, svg
, js
, or css
behind the filter to enable it.
Last updated