From 6b3933282e3aa9803636b2ba580aced5c202eaa9 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 24 Jan 2023 12:40:32 +0100 Subject: Refactor URL construction a bit BlogHTTPURL and BlogGeminiURL are now used specifically to construct absolute URLs to their respective endpoints. --- src/post/preprocess.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/post/preprocess.go') 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) -- cgit v1.2.3