diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2023-01-24 12:40:32 +0100 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2023-01-24 12:45:10 +0100 |
commit | 6b3933282e3aa9803636b2ba580aced5c202eaa9 (patch) | |
tree | afee0d9661e964a3f6f2f782bd959333c4cdaa09 /src/post | |
parent | 63cc6cb217dadc2fa5aa8d55e054cdbad14df60a (diff) |
Refactor URL construction a bit
BlogHTTPURL and BlogGeminiURL are now used specifically to construct
absolute URLs to their respective endpoints.
Diffstat (limited to 'src/post')
-rw-r--r-- | src/post/preprocess.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/post/preprocess.go b/src/post/preprocess.go index 3ec54ca..77aea81 100644 --- a/src/post/preprocess.go +++ b/src/post/preprocess.go @@ -17,12 +17,19 @@ type PreprocessFunctions struct { // The given path should not have a leading slash. BlogURL func(path string) string - // BlogURL returns the given string, rooted to the base URL of the blog's - // HTTP server (which may or may not include path components itself). + // 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 @@ -43,14 +50,15 @@ type PreprocessFunctions struct { Image func(args ...string) (string, error) } -func (funcs PreprocessFunctions) ToFuncsMap() template.FuncMap { +func (funcs PreprocessFunctions) ToFuncMap() template.FuncMap { return template.FuncMap{ - "BlogURL": funcs.BlogURL, - "BlogHTTPURL": funcs.BlogHTTPURL, - "AssetURL": funcs.AssetURL, - "PostURL": funcs.PostURL, - "StaticURL": funcs.StaticURL, - "Image": funcs.Image, + "BlogURL": funcs.BlogURL, + "BlogHTTPURL": funcs.BlogHTTPURL, + "BlogGeminiURL": funcs.BlogGeminiURL, + "AssetURL": funcs.AssetURL, + "PostURL": funcs.PostURL, + "StaticURL": funcs.StaticURL, + "Image": funcs.Image, } } @@ -61,7 +69,7 @@ func (p Post) PreprocessBody(into io.Writer, funcs PreprocessFunctions) error { tpl := template.New("") - tpl.Funcs(funcs.ToFuncsMap()) + tpl.Funcs(funcs.ToFuncMap()) tpl, err := tpl.Parse(p.Body) |