summaryrefslogtreecommitdiff
path: root/src/gmi/tpl.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2023-01-21 17:37:22 +0100
committerBrian Picciano <mediocregopher@gmail.com>2023-01-21 17:37:22 +0100
commitffdd9520b9803e141582ba647050682659075760 (patch)
treed19769360077d7b4a4cce58a0e70679014fd5979 /src/gmi/tpl.go
parent293655452cfc6a106c55384e839f9c07d340b954 (diff)
Implement preprocessing of post bodies for gemini
Diffstat (limited to 'src/gmi/tpl.go')
-rw-r--r--src/gmi/tpl.go40
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 == "" {