diff --git a/README.md b/README.md index 9ccc02e..36b2168 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,14 @@ The `uri` function takes a string and attempts to cast it to a URI, and produces {{ uri "https://schema.org/Person" }} ``` +##### Int + +The `int` function takes a value and attempts to cast it to an integer, and produces an error upon failure. + +``` +{{ int "123" }} +``` + ##### Add The `add` function sums integer values and takes at least two arguments. diff --git a/internal/template/function/utils.go b/internal/template/function/utils.go index 9591e1d..85fb083 100644 --- a/internal/template/function/utils.go +++ b/internal/template/function/utils.go @@ -21,6 +21,9 @@ var utilFuncs = map[string]interface{}{ "uri": func(value string) (rdf.IRI, error) { return rdf.NewIRI(value) }, + "int": func(value interface{}) int { + return cast.ToInt(value) + }, "config": func() config.SiteConfig { return config.CurrentSiteConfig },