func init() {
funcMap = template.FuncMap{
- "absURL": func(a string) template.HTML { return template.HTML(helpers.AbsURL(a)) },
+ "absURL": func(a interface{}) template.HTML { return template.HTML(helpers.AbsURL(cast.ToString(a))) },
"add": func(a, b interface{}) (interface{}, error) { return helpers.DoArithmetic(a, b, '+') },
"after": after,
"apply": apply,
"readDir": readDirFromWorkingDir,
"readFile": readFileFromWorkingDir,
"ref": ref,
- "relURL": func(a string) template.HTML { return template.HTML(helpers.RelURL(a)) },
+ "relURL": func(a interface{}) template.HTML { return template.HTML(helpers.RelURL(cast.ToString(a))) },
"relref": relRef,
"replace": replace,
"replaceRE": replaceRE,
in :=
`absURL: {{ "http://gohugo.io/" | absURL }}
absURL: {{ "mystyle.css" | absURL }}
+absURL: {{ 42 | absURL }}
add: {{add 1 2}}
base64Decode 1: {{ "SGVsbG8gd29ybGQ=" | base64Decode }}
base64Decode 2: {{ 42 | base64Encode | base64Decode }}
readFile: {{ readFile "README.txt" }}
relURL 1: {{ "http://gohugo.io/" | relURL }}
relURL 2: {{ "mystyle.css" | relURL }}
+relURL 2: {{ mul 2 21 | relURL }}
replace: {{ replace "Batman and Robin" "Robin" "Catwoman" }}
replaceRE: {{ "http://gohugo.io/docs" | replaceRE "^https?://([^/]+).*" "$1" }}
safeCSS: {{ "Bat&Man" | safeCSS | safeCSS }}
expected := `absURL: http://gohugo.io/
absURL: http://mysite.com/hugo/mystyle.css
+absURL: http://mysite.com/hugo/42
add: 3
base64Decode 1: Hello world
base64Decode 2: 42
readFile: Hugo Rocks!
relURL 1: http://gohugo.io/
relURL 2: /hugo/mystyle.css
+relURL 2: /hugo/42
replace: Batman and Catwoman
replaceRE: gohugo.io
safeCSS: Bat&Man