diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index 0c83f9a5f..5c65072f5 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -166,11 +166,12 @@ func (t *Template) Apply(s string) (string, error) { "time": func(s string) string { return time.Now().UTC().Format(s) }, - "tolower": strings.ToLower, - "toupper": strings.ToUpper, - "trim": strings.TrimSpace, - "dir": filepath.Dir, - "abs": filepath.Abs, + "tolower": strings.ToLower, + "toupper": strings.ToUpper, + "trim": strings.TrimSpace, + "trimprefix": strings.TrimPrefix, + "dir": filepath.Dir, + "abs": filepath.Abs, }). Parse(s) if err != nil { diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index 62e3ac0f8..8835c79bd 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -188,6 +188,11 @@ func TestFuncMap(t *testing.T) { Name: "tolower", Expected: "test", }, + { + Template: `{{ trimprefix "v1.2.4" "v" }}`, + Name: "trimprefix", + Expected: "1.2.4", + }, { Template: `{{ toupper "test" }}`, Name: "toupper", diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index ae20a794c..11328ba33 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -62,6 +62,7 @@ On all fields, you have these available functions: | `tolower "V1.2"` | makes input string lowercase. See [ToLower](https://golang.org/pkg/strings/#ToLower) | | `toupper "v1.2"` | makes input string uppercase. See [ToUpper](https://golang.org/pkg/strings/#ToUpper) | | `trim " v1.2 "` | removes all leading and trailing white space. See [TrimSpace](https://golang.org/pkg/strings/#TrimSpace) | +| `trimprefix "v1.2" "v"` | removes provided leading prefix string, if present. See [TrimSpace](https://golang.org/pkg/strings/#TrimPrefix) | | `dir .Path` | returns all but the last element of path, typically the path's directory. See [Dir](https://golang.org/pkg/path/filepath/#Dir) | | `abs .ArtifactPath` | returns an absolute representation of path. See [Abs](https://golang.org/pkg/path/filepath/#Abs) |