From 16cfbd19157df76e7296dddb287412f1099feb33 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 20 May 2022 13:37:43 -0600 Subject: Move static assets to within srv --- srv/src/http/tpl.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'srv/src/http/tpl.go') diff --git a/srv/src/http/tpl.go b/srv/src/http/tpl.go index d647317..65f23a7 100644 --- a/srv/src/http/tpl.go +++ b/srv/src/http/tpl.go @@ -31,10 +31,12 @@ func (a *api) mustParseTpl(name string) *template.Template { blogURL := func(path string) string { + // filepath.Join strips trailing slash, but we want to keep it trailingSlash := strings.HasSuffix(path, "/") - path = filepath.Join(a.params.PathPrefix, "/v2", path) - if trailingSlash { + path = filepath.Join("/", a.params.PathPrefix, path) + + if trailingSlash && path != "/" { path += "/" } @@ -43,6 +45,10 @@ func (a *api) mustParseTpl(name string) *template.Template { tpl := template.New("").Funcs(template.FuncMap{ "BlogURL": blogURL, + "StaticURL": func(path string) string { + path = filepath.Join("static", path) + return blogURL(path) + }, "AssetURL": func(id string) string { path := filepath.Join("assets", id) return blogURL(path) -- cgit v1.2.3