diff options
Diffstat (limited to 'src/gmi')
-rw-r--r-- | src/gmi/posts_preprocess_funcs.go | 26 | ||||
-rw-r--r-- | src/gmi/tpl.go | 24 |
2 files changed, 31 insertions, 19 deletions
diff --git a/src/gmi/posts_preprocess_funcs.go b/src/gmi/posts_preprocess_funcs.go new file mode 100644 index 0000000..f8fcda6 --- /dev/null +++ b/src/gmi/posts_preprocess_funcs.go @@ -0,0 +1,26 @@ +package gmi + +import ( + "fmt" + + "dev.mediocregopher.com/mediocre-blog.git/src/render" +) + +type postPreprocessFuncs struct { + urlBuilder render.URLBuilder +} + +func (f postPreprocessFuncs) Image(args ...string) (string, error) { + var ( + id = args[0] + descr = "Image" + ) + + if len(args) > 1 { + descr = args[1] + } + + return fmt.Sprintf( + "\n=> %s %s", f.urlBuilder.Asset(id), descr, + ), nil +} diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go index fb62a17..5ea114d 100644 --- a/src/gmi/tpl.go +++ b/src/gmi/tpl.go @@ -34,24 +34,10 @@ var tplFS embed.FS func (a *api) tplHandler() (gemini.Handler, error) { - preprocessFuncs := post.PreprocessFunctions{ - Image: func(args ...string) (string, error) { - var ( - id = args[0] - descr = "Image" - ) - - if len(args) > 1 { - descr = args[1] - } - - return fmt.Sprintf( - "\n=> %s %s", a.urlBuilder.Asset(id), descr, - ), nil - }, - } - - allTpls := template.New("") + var ( + postPreprocessFuncs = postPreprocessFuncs{a.urlBuilder} + allTpls = template.New("") + ) err := fs.WalkDir(tplFS, "tpl", func(path string, d fs.DirEntry, err error) error { @@ -122,7 +108,7 @@ func (a *api) tplHandler() (gemini.Handler, error) { a.params.PostStore, nil, // asset.Store, not supported by gemini endpoint nil, // post.DraftStore, not supported by gemini endpoint - preprocessFuncs, + postPreprocessFuncs, )) if errors.Is(err, post.ErrPostNotFound) { |