summaryrefslogtreecommitdiff
path: root/src/gmi/tpl.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2023-01-22 14:12:54 +0100
committerBrian Picciano <mediocregopher@gmail.com>2023-01-22 14:12:54 +0100
commitacec797048301c7d8713d9c914d776929c51b088 (patch)
tree5339ede42c5f07760b2d4a27f4b920bdbf27f328 /src/gmi/tpl.go
parent5b5a0438682ecb69bbc8d7cb9904ad4b049033a3 (diff)
Final fleshing out of gemini content
Diffstat (limited to 'src/gmi/tpl.go')
-rw-r--r--src/gmi/tpl.go18
1 files changed, 16 insertions, 2 deletions
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,
})