From 0665d0c65974533fbd313f4e0b062b5103057aeb Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 18 May 2024 18:29:19 +0200 Subject: Replace all URL rendering within templates by a URLConstructor --- src/http/http.go | 5 ++++- src/http/posts.go | 6 ++++++ src/http/tpl.go | 2 ++ src/http/tpl/admin.html | 6 +++--- src/http/tpl/base.html | 22 +++++++++++----------- src/http/tpl/draft-posts-manage.html | 14 +++++++------- src/http/tpl/follow.html | 2 +- src/http/tpl/gemini-cta.html | 6 ++---- src/http/tpl/image.html | 4 ++-- src/http/tpl/index.html | 6 +++--- src/http/tpl/post-assets-manage.html | 8 ++++---- src/http/tpl/post-edit.html | 16 ++++++++-------- src/http/tpl/post.html | 4 ++-- src/http/tpl/posts-manage.html | 14 +++++++------- src/http/tpl/posts.html | 8 ++++---- 15 files changed, 66 insertions(+), 57 deletions(-) (limited to 'src/http') diff --git a/src/http/http.go b/src/http/http.go index 9bfed59..93cc043 100644 --- a/src/http/http.go +++ b/src/http/http.go @@ -89,7 +89,10 @@ func (p *Params) SetupCfg(cfg *cfg.Cfg) { return fmt.Errorf("unmarshaling -http-auth-ratelimit: %w", err) } - *publicURLStr = strings.TrimSuffix(*publicURLStr, "/") + if !strings.HasSuffix(*publicURLStr, "/") { + *publicURLStr += "/" + } + if p.PublicURL, err = url.Parse(*publicURLStr); err != nil { return fmt.Errorf("parsing -http-public-url: %w", err) } diff --git a/src/http/posts.go b/src/http/posts.go index 14224f2..42e5b4a 100644 --- a/src/http/posts.go +++ b/src/http/posts.go @@ -40,10 +40,16 @@ func (a *api) postPreprocessFuncImage(args ...string) (string, error) { tpl = txttpl.Must(tpl.Parse(mustReadTplFile("image.html"))) tplPayload := struct { + RootURL render.URLBuilder ID string Descr string Resizable bool }{ + RootURL: render.NewURLBuilder( + a.params.PublicURL, + a.params.PublicURL, // httpURL + a.params.GeminiPublicURL, + ), ID: id, Descr: descr, Resizable: asset.IsImageResizable(id), diff --git a/src/http/tpl.go b/src/http/tpl.go index 2711259..c4afbdc 100644 --- a/src/http/tpl.go +++ b/src/http/tpl.go @@ -135,6 +135,8 @@ func (a *api) newTPLData(r *http.Request, payload interface{}) tplData { r.Context(), r.URL, a.params.PublicURL, + a.params.PublicURL, // httpURL + a.params.GeminiPublicURL, a.params.GeminiGatewayURL, a.params.PostStore, a.params.PostAssetStore, diff --git a/src/http/tpl/admin.html b/src/http/tpl/admin.html index 0b4b4e3..2dfab0f 100644 --- a/src/http/tpl/admin.html +++ b/src/http/tpl/admin.html @@ -7,9 +7,9 @@ mostly left open to inspection, but you will not able to change anything without providing credentials. {{ end }} diff --git a/src/http/tpl/base.html b/src/http/tpl/base.html index 47644f7..f0419d5 100644 --- a/src/http/tpl/base.html +++ b/src/http/tpl/base.html @@ -3,12 +3,12 @@ {{ .Title }} - - - - - - + + + + + + @@ -105,17 +105,17 @@ mediocregopher's lil web corner

- Home + Home  //  - Posts + Posts  /  - Follow + Follow  /  - RSS + RSS  //  Source  /  - License + License {{ template "body" . }} diff --git a/src/http/tpl/draft-posts-manage.html b/src/http/tpl/draft-posts-manage.html index b1b4362..417f716 100644 --- a/src/http/tpl/draft-posts-manage.html +++ b/src/http/tpl/draft-posts-manage.html @@ -1,6 +1,6 @@ {{ define "body" }} - {{ $page := .GetQueryIntValue "p" 0 -}} + {{ $page := .GetQueryIntValue "page" 0 -}} {{ $getPostsRes := .GetDraftPosts $page 20 -}}

- Back to Admin + Back to Admin

Drafts

- New Draft + New Draft

{{ if gt $page 0 }}

- < < Previous Page + < < Previous Page

{{ end }} @@ -32,13 +32,13 @@ {{ .Title }} - + Edit
- Next Page > > + Next Page > >

{{ end }} diff --git a/src/http/tpl/follow.html b/src/http/tpl/follow.html index 1958f95..091af49 100644 --- a/src/http/tpl/follow.html +++ b/src/http/tpl/follow.html @@ -6,7 +6,7 @@

- {{ BlogHTTPURL "feed.xml" }} + {{ .RootURL.Absolute.Path "feed.xml" }}

diff --git a/src/http/tpl/gemini-cta.html b/src/http/tpl/gemini-cta.html index 89b8e8b..77c1114 100644 --- a/src/http/tpl/gemini-cta.html +++ b/src/http/tpl/gemini-cta.html @@ -2,11 +2,9 @@

This site can also be accessed via the gemini protocol: - - {{ BlogGeminiURL "/" }} - + {{ .RootURL.Gemini.HTMLSafe }}

- What is gemini? + What is gemini?

diff --git a/src/http/tpl/image.html b/src/http/tpl/image.html index c6c19b3..7778625 100644 --- a/src/http/tpl/image.html +++ b/src/http/tpl/image.html @@ -1,7 +1,7 @@
- + {{ .Descr }} diff --git a/src/http/tpl/index.html b/src/http/tpl/index.html index 7f6399a..2685f4f 100644 --- a/src/http/tpl/index.html +++ b/src/http/tpl/index.html @@ -2,9 +2,9 @@

This here's my little corner of the web, where I publish - posts + posts about projects I'm working on and things that interest me (which you can - follow, + follow, if you like).

@@ -12,7 +12,7 @@

Feel free to hmu over email or Signal if you'd like to get in touch.

  • Email: me@mediocregopher.com
  • -
  • GPG Key
  • +
  • GPG Key
  • Signal: mediocregopher.01 diff --git a/src/http/tpl/post-assets-manage.html b/src/http/tpl/post-assets-manage.html index a0b0da0..7e01ff4 100644 --- a/src/http/tpl/post-assets-manage.html +++ b/src/http/tpl/post-assets-manage.html @@ -3,7 +3,7 @@ {{ $assetIDs := .GetPostAssetIDs }}

    - Back to Admin + Back to Admin

    Assets

    @@ -15,7 +15,7 @@ overwritten.

    - +
    @@ -37,10 +37,10 @@ {{ range $assetIDs }} - {{ . }} + {{ . }} diff --git a/src/http/tpl/post-edit.html b/src/http/tpl/post-edit.html index 28dcd0e..1c40a3a 100644 --- a/src/http/tpl/post-edit.html +++ b/src/http/tpl/post-edit.html @@ -6,17 +6,17 @@

    {{ if .Payload.IsDraft }} - + Back to Drafts {{ else }} - + Back to Posts {{ end }}

    - + @@ -36,7 +36,7 @@ {{ $post.ID }} {{ else }} - {{ $post.ID }} + {{ $post.ID }} {{ end }} @@ -135,12 +135,12 @@ {{ if .Payload.IsDraft }} - +

    - Back to Admin + Back to Admin

    Posts

    {{ if gt $page 0 }}

    - < < Previous Page + < < Previous Page

    {{ end }} @@ -33,15 +33,15 @@ {{ range $getPostsRes.Posts }} - +
    {{ .PublishedAt.Local.Format "2006-01-02 15:04:05 MST" }}{{ .Title }}{{ .Title }} - + Edit - Next Page > > + Next Page > >

    {{ end }} diff --git a/src/http/tpl/posts.html b/src/http/tpl/posts.html index 2fa336d..0df166a 100644 --- a/src/http/tpl/posts.html +++ b/src/http/tpl/posts.html @@ -1,11 +1,11 @@ {{ define "body" }} - {{ $page := .GetQueryIntValue "p" 0 -}} + {{ $page := .GetQueryIntValue "page" 0 -}} {{ $getPostsRes := .GetPosts $page 20 -}} {{ if gt $page 0 }}

    - < < Previous Page + < < Previous Page

    {{ else }}

    @@ -17,7 +17,7 @@