From 1cfdac5e8c2ac802275cb29ae9149c55547f38fb Mon Sep 17 00:00:00 2001
From: Brian Picciano
Date: Sun, 22 Jan 2023 12:09:50 +0100
Subject: Allow url construction to work if blog is under a sub-path
---
src/gmi/tpl.go | 4 +++-
src/http/tpl.go | 9 +++++++--
src/http/tpl/follow.html | 2 +-
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go
index e448afd..c648abd 100644
--- a/src/gmi/tpl.go
+++ b/src/gmi/tpl.go
@@ -37,6 +37,7 @@ type rendererGetPostSeriesNextPreviousRes struct {
type renderer struct {
url *url.URL
postStore post.Store
+ gmiPublicURL *url.URL
httpPublicURL *url.URL
}
@@ -92,7 +93,7 @@ func (r renderer) PostBody(p post.StoredPost) (string, error) {
preprocessFuncs := post.PreprocessFunctions{
BlogURL: func(path string) string {
- return filepath.Join("/", path)
+ return filepath.Join("/", r.gmiPublicURL.Path, path)
},
AssetURL: func(id string) string {
return filepath.Join("/assets", id)
@@ -220,6 +221,7 @@ func (a *api) tplHandler() (gemini.Handler, error) {
err := tpl.Execute(buf, renderer{
url: r.URL,
postStore: a.params.PostStore,
+ gmiPublicURL: a.params.PublicURL,
httpPublicURL: a.params.HTTPPublicURL,
})
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)
diff --git a/src/http/tpl/follow.html b/src/http/tpl/follow.html
index eabf8ea..c0e4980 100644
--- a/src/http/tpl/follow.html
+++ b/src/http/tpl/follow.html
@@ -114,7 +114,7 @@ emailSubscribe.onclick = async () => {
- {{ BlogURL "feed.xml" }}
+ {{ BlogURLAbs "feed.xml" }}
--
cgit v1.2.3