summaryrefslogtreecommitdiff
path: root/src/post
diff options
context:
space:
mode:
Diffstat (limited to 'src/post')
-rw-r--r--src/post/preprocess.go71
1 files changed, 0 insertions, 71 deletions
diff --git a/src/post/preprocess.go b/src/post/preprocess.go
index 77aea81..7aceee2 100644
--- a/src/post/preprocess.go
+++ b/src/post/preprocess.go
@@ -1,46 +1,9 @@
package post
-import (
- "fmt"
- "io"
- "text/template"
-)
-
// PreprocessFunctions are functions which can be used by posts themselves to
// interleave dynamic content into their bodies. Usually this is used for
// properly constructing URLs, but also for things like displaying images.
type PreprocessFunctions struct {
-
- // BlogURL returns the given string, rooted to the blog's base url (which
- // may or may not include path components itself).
- //
- // The given path should not have a leading slash.
- BlogURL func(path string) string
-
- // BlogHTTPURL returns the given string, rooted to the base URL of the
- // blog's HTTP server (which may or may not include path components itself).
- //
- // The given path should not have a leading slash.
- BlogHTTPURL func(path string) string
-
- // BlogGeminiURL returns the given string, rooted to the base URL of the
- // blog's gemini server (which may or may not include path components
- // itself).
- //
- // The given path should not have a leading slash.
- BlogGeminiURL func(path string) string
-
- // AssetURL returns the URL of the asset with the given ID.
- AssetURL func(id string) string
-
- // PostURL returns the URL of the post with the given ID.
- PostURL func(id string) string
-
- // StaticURL returns the URL of a file being served from the static
- // directory. The given path should _not_ include the prefixed 'static/'
- // path element.
- StaticURL func(path string) string
-
// Image returns a string which should be inlined into the post body in
// order to display an.
//
@@ -49,37 +12,3 @@ type PreprocessFunctions struct {
// alt text, or possibly displayed to the user with the image.
Image func(args ...string) (string, error)
}
-
-func (funcs PreprocessFunctions) ToFuncMap() template.FuncMap {
- return template.FuncMap{
- "BlogURL": funcs.BlogURL,
- "BlogHTTPURL": funcs.BlogHTTPURL,
- "BlogGeminiURL": funcs.BlogGeminiURL,
- "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.
-func (p Post) PreprocessBody(into io.Writer, funcs PreprocessFunctions) error {
-
- tpl := template.New("")
-
- tpl.Funcs(funcs.ToFuncMap())
-
- tpl, err := tpl.Parse(p.Body)
-
- if err != nil {
- return fmt.Errorf("parsing post body as template: %w", err)
- }
-
- if err := tpl.Execute(into, nil); err != nil {
- return fmt.Errorf("executing post body as template: %w", err)
- }
-
- return nil
-}