Commit 9df917e73a

9df917e73a67d15adecc3f45976690f6fcd4e47a

parent: 145dec111d

Verified · cmc ci/build: success ci/test: success

cmc <hello@cleberg.net> · 2026-09-28 22:34 UTC

wiki: a link to an existing non-page file resolves to _raw, not the page route

Closes #283

Layout: unified · split

CHANGELOG.org +4
@@ -6,6 +6,10 @@ anything beyond "replace the binary and restart" is needed.
66
77* Unreleased
88
9- A wiki link to an existing non-page file (an .svg, .txt, .pdf) now
10 resolves to the raw route instead of 404ing against the page route
11 (#283).
12
913- The new-issue form takes labels, milestone and assignee in one step
1014 for writers; the watch button names watching, muted and default; a
1115 Discussion heading sits before comment threads; the build page's
internal/httpd/wiki.go +9 −1
@@ -248,8 +248,16 @@ func rewriteWikiLinks(rendered template.HTML, p repoPage, page string, isPage, i
248248 }
249249 continue
250250 }
251 // A plain link is usually to another page, but a link to
252 // an existing non-page file (an .svg, .txt, .pdf) must
253 // go to _raw the same as an image src, or it 404s
254 // against the page route (#283).
251255 if target, ok := wikiResolve(page, trimPageExt(v), isPage); ok {
252 n.Attr[i].Val = base + "/" + target
256 if raw, rok := wikiResolve(page, v, isFile); rok && isFile(raw) && !isPage(target) {
257 n.Attr[i].Val = base + "/_raw/" + raw
258 } else {
259 n.Attr[i].Val = base + "/" + target
260 }
253261 }
254262 }
255263 }
internal/httpd/wiki_test.go +2
@@ -41,12 +41,14 @@ func TestRewriteWikiLinksInSubfolder(t *testing.T) {
4141 pages := map[string]bool{"Admin": true, "Architecture/Identity": true}
4242 files := map[string]bool{"diagrams/a.svg": true, "Architecture/b.svg": true}
4343 in := template.HTML(`<a href="Identity.org">i</a><a href="Admin.org">a</a>` +
44 `<a href="b.svg">diagram</a>` +
4445 `<img src="b.svg"><img src="diagrams/a.svg"><a href="https://x.test/">x</a>`)
4546 out := string(rewriteWikiLinks(in, p, "Architecture/Trust",
4647 func(s string) bool { return pages[s] }, func(s string) bool { return files[s] }))
4748 for _, want := range []string{
4849 `href="/krz/gitbay/wiki/Architecture/Identity"`,
4950 `href="/krz/gitbay/wiki/Admin"`,
51 `href="/krz/gitbay/wiki/_raw/Architecture/b.svg"`,
5052 `src="/krz/gitbay/wiki/_raw/Architecture/b.svg"`,
5153 `src="/krz/gitbay/wiki/_raw/diagrams/a.svg"`,
5254 `href="https://x.test/"`,