diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2023-01-22 12:09:50 +0100 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2023-01-22 12:09:50 +0100 |
commit | 1cfdac5e8c2ac802275cb29ae9149c55547f38fb (patch) | |
tree | 005d493ab0d235c9b7f2c488343fb10f9642be50 /src/http/tpl.go | |
parent | f536b16e170a5efb5b3bdd720e48100d5d0f83ba (diff) |
Allow url construction to work if blog is under a sub-path
Diffstat (limited to 'src/http/tpl.go')
-rw-r--r-- | src/http/tpl.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/http/tpl.go b/src/http/tpl.go index f49232a..5fc54f3 100644 --- a/src/http/tpl.go +++ b/src/http/tpl.go @@ -31,14 +31,16 @@ func (a *api) blogURL(path string, abs bool) string { // filepath.Join strips trailing slash, but we want to keep it trailingSlash := strings.HasSuffix(path, "/") - res := filepath.Join("/", path) + res := filepath.Join("/", a.params.PublicURL.Path, path) if trailingSlash && res != "/" { res += "/" } if abs { - res = a.params.PublicURL.String() + res + u := *a.params.PublicURL + u.Path = res + res = u.String() } return res @@ -88,6 +90,9 @@ func (a *api) tplFuncs() template.FuncMap { "BlogURL": func(path string) string { return a.blogURL(path, false) }, + "BlogURLAbs": func(path string) string { + return a.blogURL(path, true) + }, "StaticURL": func(path string) string { path = filepath.Join("static", path) return a.blogURL(path, false) |