]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl: Add hasSuffix alias
authorJonathan Fisher <jonathan@trueanthem.com>
Wed, 1 Mar 2023 22:29:33 +0000 (14:29 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 8 Mar 2023 09:18:34 +0000 (10:18 +0100)
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
docs/content/en/functions/hasSuffix.md [new file with mode: 0644]
tpl/strings/init.go

index 99d5ba8190ec080d71e1a9ad3b0e0a32e4467e2b..cf29315e26eefca35c4bcc69c374edae92ccc0ec 100644 (file)
@@ -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 (file)
index 0000000..9906cc2
--- /dev/null
@@ -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
index 37a48912852d0d5b958c573a22257493d5aa6693..b236d110a54f4e513ed31c19645a5bd25a05ac16 100644 (file)
@@ -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{