pico
created pr with
pico/prose-redirect-slash.1
cmds
checkout latest patchset:
ssh pr.pico.sh pull pico:prose-redirect-slash | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull pico:prose-redirect-slash [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pico:prose-redirect-slashadd comment to patch request:
ssh pr.pico.sh comment pico:prose-redirect-slash "lgtm!"
Patchset
pico/prose-redirect-slash.1
chore(prose): trailing `/{post}/` 301 redirect to `/{post`
Eric Bower
2026-11-27T14:39:56ZWe treat both posts the same but any cdn/analytics will treat them as potentially distinct so as part of best practices we collapse them with a redirect. Prose uses the bare post as the canonical url so we want to trim the trailing `/`.
Semantic diff summary
0 added,
0 modified,
0 signature changed,
0 removed
across 1 analyzed file
+12
-0
pkg/apps/prose/api.go
#
| ... | ... | @@ -946,11 +946,23 @@ var ( | |
| 946 | 946 | // A "/raw/{slug...}" pattern would redirect "/raw" away from a post named raw. | |
| 947 | 947 | func (web *webRouter) pathRoute(w http.ResponseWriter, r *http.Request) { | |
| 948 | 948 | path := r.PathValue("path") | |
| 949 | + | ||
| 950 | + | // remove trailing `/` suffix and 301 redirect as part of best practices | |
| 951 | + | if strings.HasSuffix(path, "/") { | |
| 952 | + | nextUrl := fmt.Sprintf("/%s", strings.TrimSuffix(path, "/")) | |
| 953 | + | if r.URL.RawQuery != "" { | |
| 954 | + | nextUrl = fmt.Sprintf("%s?%s", nextUrl, r.URL.RawQuery) | |
| 955 | + | } | |
| 956 | + | http.Redirect(w, r, nextUrl, http.StatusMovedPermanently) | |
| 957 | + | return | |
| 958 | + | } | |
| 959 | + | ||
| 949 | 960 | if slug, ok := strings.CutPrefix(path, "raw/"); ok && slug != "" { | |
| 950 | 961 | r.SetPathValue("slug", slug) | |
| 951 | 962 | web.postRawHandler(w, r) | |
| 952 | 963 | return | |
| 953 | 964 | } | |
| 965 | + | ||
| 954 | 966 | for _, ext := range []string{".md", ".gmi"} { | |
| 955 | 967 | if slug, ok := strings.CutSuffix(path, ext); ok && slug != "" { | |
| 956 | 968 | r.SetPathValue("slug", slug) |