From acec797048301c7d8713d9c914d776929c51b088 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 22 Jan 2023 14:12:54 +0100 Subject: Final fleshing out of gemini content --- src/gmi/tpl.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/gmi/tpl.go') diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go index edd3a75..8f4c3be 100644 --- a/src/gmi/tpl.go +++ b/src/gmi/tpl.go @@ -36,6 +36,7 @@ type rendererGetPostSeriesNextPreviousRes struct { type renderer struct { url *url.URL + publicURL *url.URL postStore post.Store preprocessFuncs post.PreprocessFunctions } @@ -124,12 +125,24 @@ func (r renderer) GetQueryIntValue(key string, def int) (int, error) { return strconv.Atoi(vStr) } +func (r renderer) GetPath() (string, error) { + basePath := filepath.Join("/", r.publicURL.Path) // in case it's empty + return filepath.Rel(basePath, r.url.Path) +} + func (r renderer) Add(a, b int) int { return a + b } func (a *api) tplHandler() (gemini.Handler, error) { blogURL := func(path string, abs bool) string { - path = filepath.Join(a.params.PublicURL.Path, path) + // filepath.Join strips trailing slash, but we want to keep it + trailingSlash := strings.HasSuffix(path, "/") + + path = filepath.Join("/", a.params.PublicURL.Path, path) + + if trailingSlash && path != "/" { + path += "/" + } if !abs { return path @@ -170,7 +183,7 @@ func (a *api) tplHandler() (gemini.Handler, error) { path := blogURL(filepath.Join("assets", id), false) - return fmt.Sprintf("=> %s %s", path, descr), nil + return fmt.Sprintf("\n=> %s %s", path, descr), nil }, } @@ -247,6 +260,7 @@ func (a *api) tplHandler() (gemini.Handler, error) { err := tpl.Execute(buf, renderer{ url: r.URL, + publicURL: a.params.PublicURL, postStore: a.params.PostStore, preprocessFuncs: preprocessFuncs, }) -- cgit v1.2.3