diff options
Diffstat (limited to 'src/gmi/tpl.go')
-rw-r--r-- | src/gmi/tpl.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go index 7959b8e..7f41993 100644 --- a/src/gmi/tpl.go +++ b/src/gmi/tpl.go @@ -8,6 +8,7 @@ import ( "io" "io/fs" "net/url" + "path/filepath" "strconv" "strings" "text/template" @@ -83,6 +84,45 @@ func (r renderer) GetPostSeriesNextPrevious(p post.StoredPost) (rendererGetPostS return res, nil } +func (r renderer) PostBody(p post.StoredPost) (string, error) { + + preprocessFuncs := post.PreprocessFunctions{ + BlogURL: func(path string) string { + return filepath.Join("/", path) + }, + AssetURL: func(id string) string { + return filepath.Join("/assets", id) + }, + PostURL: func(id string) string { + return filepath.Join("/posts", id) + }, + StaticURL: func(path string) string { + return filepath.Join("/static", path) + }, + Image: func(args ...string) (string, error) { + + var ( + id = args[0] + descr = "Image" + ) + + if len(args) > 1 { + descr = args[1] + } + + return fmt.Sprintf("=> %s %s", filepath.Join("/assets", id), descr), nil + }, + } + + buf := new(bytes.Buffer) + + if err := p.PreprocessBody(buf, preprocessFuncs); err != nil { + return "", fmt.Errorf("preprocessing post body: %w", err) + } + + return buf.String(), nil +} + func (r renderer) GetQueryValue(key, def string) string { v := r.url.Query().Get(key) if v == "" { |