summaryrefslogtreecommitdiff
path: root/src/post
diff options
context:
space:
mode:
Diffstat (limited to 'src/post')
-rw-r--r--src/post/preprocess.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/post/preprocess.go b/src/post/preprocess.go
index 4d4be9d..424c7b8 100644
--- a/src/post/preprocess.go
+++ b/src/post/preprocess.go
@@ -37,6 +37,16 @@ type PreprocessFunctions struct {
Image func(args ...string) (string, error)
}
+func (funcs PreprocessFunctions) ToFuncsMap() template.FuncMap {
+ return template.FuncMap{
+ "BlogURL": funcs.BlogURL,
+ "AssetURL": funcs.AssetURL,
+ "PostURL": funcs.PostURL,
+ "StaticURL": funcs.StaticURL,
+ "Image": funcs.Image,
+ }
+}
+
// PreprocessBody interprets the Post's Body as a text template which may use
// any of the functions found in PreprocessFunctions (all must be set). It
// executes the template and writes the result to the given writer.
@@ -44,13 +54,7 @@ func (p Post) PreprocessBody(into io.Writer, funcs PreprocessFunctions) error {
tpl := template.New("")
- tpl.Funcs(template.FuncMap{
- "BlogURL": funcs.BlogURL,
- "AssetURL": funcs.AssetURL,
- "PostURL": funcs.PostURL,
- "StaticURL": funcs.StaticURL,
- "Image": funcs.Image,
- })
+ tpl.Funcs(funcs.ToFuncsMap())
tpl, err := tpl.Parse(p.Body)