aboutsummaryrefslogtreecommitdiff
path: root/page/page.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2022-12-07 11:29:15 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2022-12-07 11:29:15 -0500
commit69a3d0123be4c645d5318b5e9d0a5e68f6324b58 (patch)
treebb45de12a811b2f9aa135c7d7af825754291c259 /page/page.go
parent10c60b3c9ba2c17419534cf4089328a66568e4f1 (diff)
downloadgo-website-69a3d0123be4c645d5318b5e9d0a5e68f6324b58.tar.gz
go-website-69a3d0123be4c645d5318b5e9d0a5e68f6324b58.tar.xz
Add basic string functions to default template funcmap. Set a var when page is being rendered markdown only.v0.0.20
Diffstat (limited to 'page/page.go')
-rw-r--r--page/page.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/page/page.go b/page/page.go
index 29b35bc..214021e 100644
--- a/page/page.go
+++ b/page/page.go
@@ -33,6 +33,8 @@ import (
"log"
"os"
"path/filepath"
+ "regexp"
+ "strings"
"text/template"
"github.com/russross/blackfriday"
@@ -67,7 +69,22 @@ type Page struct {
var Global interface{}
// Funcs accessible to the templates.
-var Funcs template.FuncMap
+var Funcs template.FuncMap = template.FuncMap{
+ "join": strings.Join,
+ "split": strings.Split,
+ "toLower": strings.ToLower,
+ "toUpper": strings.ToUpper,
+ "replace": strings.Replace,
+ "replaceAll": strings.ReplaceAll,
+ "toTitle": strings.ToTitle,
+ "hasPrefix": strings.HasPrefix,
+ "hasSuffix": strings.HasSuffix,
+ "trimPrefix": strings.TrimPrefix,
+ "trimSuffix": strings.TrimSuffix,
+ "regexpReplaceAll": func(s, regex, rep string) string {
+ return regexp.MustCompile(regex).ReplaceAllString(s, rep)
+ },
+}
// CacheIndex determines whether or not the index will be cached in memory
// or rebuilt on each call.