davidsneighbour / hugo-modules

A mono repo for all GoHugo modules by @davidsneighbour.
https://github.com/davidsneighbour/hugo-modules
MIT License
4 stars 1 forks source link

hooks: hand data to a filter hook and return transformed data #20

Open davidsneighbour opened 2 years ago

davidsneighbour commented 2 years ago

WordPress filter feature for GoHugo basically. Hand data to a filter(-hook) partial and if a filter partial exists for that filter term then run the data through it and return whats returned or the data unchanged.

davidsneighbour commented 8 months ago

Call:

{{- $filteredValue := partials.Include "func/filter.html" ( collections.Dictionary 
                                            "filter" "filtername" 
                                            "context" . ) -}}

The required parameter is filter with the filter name. everything else depends on the filter and its documentation.

Configuration (copy paste from the current hooks docs):

Module based hooks (plugin hooks)

In params.toml (or under the [params] section of the configuration) add a table array as such:

[[dnb.hooks.filters.namespace.filtername]]
file = "partial path"
weight = "integer"
cached = "boolean/string"

# proper sample
[[dnb.hooks.filters.namespace.urlfilter]]
file = "func/urlfilter.html"
weight = 100
cached = false

Notes:

Note that the cached option is a work in progress. I'll need to find ways to cache, for instance, according to section. This might change over time.-

davidsneighbour commented 8 months ago

WIP: see 5669337d51e92ced5888c5960dc8dba29ecdbfac and 36a03c33ad2ba2cf718a4414d129fd5182d21a89