cerca

lean forum software (pmc local branch)
Log | Files | Refs | README | LICENSE

commit 8ac3113b2a598a33cc2c787e2cbd95b550762c8d
parent 6a8aeb32ed1837379ca8e447215068d5e42a381f
Author: cblgh <cblgh@cblgh.org>
Date:   Mon, 12 Dec 2022 15:54:34 +0100

better join path procedure

Diffstat:
Mserver/server.go | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/server/server.go b/server/server.go @@ -360,6 +360,12 @@ func IndexRedirect(res http.ResponseWriter, req *http.Request) { const rfc822RSS = "Mon, 02 Jan 2006 15:04:05 -0700" +func joinPath(host, upath string) string { + host = strings.TrimSuffix(host, "/") + upath = strings.TrimPrefix(upath, "/") + return fmt.Sprintf("%s/%s", host, upath) +} + func GenerateRSS(db *database.DB, config types.Config) string { if config.RSS.URL == "" { return "feed not configured" @@ -371,7 +377,7 @@ func GenerateRSS(db *database.DB, config types.Config) string { for i, t := range threads { fulltime := t.Publish.Format(rfc822RSS) date := t.Publish.Format("2006-01-02") - posturl := filepath.Join(config.RSS.URL, fmt.Sprintf("%s#%d", t.Slug, t.PostID)) + posturl := joinPath(config.RSS.URL, fmt.Sprintf("%s#%d", t.Slug, t.PostID)) entry := rss.OutputRSSItem(fulltime, t.Title, fmt.Sprintf("[%s] %s posted", date, t.Author), posturl) entries[i] = entry }