From d171d1543d6df3f93a368c240a247513e5b7da44 Mon Sep 17 00:00:00 2001 From: Jonathan Fisher Date: Wed, 1 Mar 2023 14:29:33 -0800 Subject: [PATCH] tpl: Add hasSuffix alias strings.HasPrefix already has an alias of hasPrefix but strings.HasSuffix has no such alias. This PR adds a hasSuffix alias to the tpl function with corresponding function documentation. It also adds a Minor update to the hasPrefix function documentation re: keywords and relatedfuncs. Completes https://github.com/gohugoio/hugo/issues/10474 --- docs/content/en/functions/hasPrefix.md | 4 ++-- docs/content/en/functions/hasSuffix.md | 21 +++++++++++++++++++++ tpl/strings/init.go | 8 ++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 docs/content/en/functions/hasSuffix.md diff --git a/docs/content/en/functions/hasPrefix.md b/docs/content/en/functions/hasPrefix.md index 99d5ba8190e..cf29315e26e 100644 --- a/docs/content/en/functions/hasPrefix.md +++ b/docs/content/en/functions/hasPrefix.md @@ -9,11 +9,11 @@ categories: [functions] menu: docs: parent: "functions" -keywords: [] +keywords: [strings] signature: ["hasPrefix STRING PREFIX"] workson: [] hugoversion: -relatedfuncs: [] +relatedfuncs: [hasSuffix] deprecated: false aliases: [] --- diff --git a/docs/content/en/functions/hasSuffix.md b/docs/content/en/functions/hasSuffix.md new file mode 100644 index 00000000000..9906cc2c3be --- /dev/null +++ b/docs/content/en/functions/hasSuffix.md @@ -0,0 +1,21 @@ +--- +title: hassuffix +linktitle: hasSuffix +description: Tests whether a string ends with suffix. +date: 2023-03-01 +publishdate: 2023-03-01 +lastmod: 2023-03-01 +categories: [functions] +menu: +docs: +parent: "functions" +keywords: [strings] +signature: ["hasSuffix STRING SUFFIX"] +workson: [] +hugoversion: +relatedfuncs: [hasPrefix] +deprecated: false +aliases: [] +--- + +* `{{ hasSuffix "Hugo" "go" }}` → true \ No newline at end of file diff --git a/tpl/strings/init.go b/tpl/strings/init.go index 37a48912852..b236d110a54 100644 --- a/tpl/strings/init.go +++ b/tpl/strings/init.go @@ -104,6 +104,14 @@ func init() { }, ) + ns.AddMethodMapping(ctx.HasSuffix, + []string{"hasSuffix"}, + [][2]string{ + {`{{ hasSuffix "Hugo" "go" }}`, `true`}, + {`{{ hasSuffix "Hugo" "du" }}`, `false`}, + }, + ) + ns.AddMethodMapping(ctx.ToLower, []string{"lower"}, [][2]string{