Redesign source link

This commit is contained in:
2026-09-13 12:45:44 +02:00
parent 27be685834
commit 132e7c41d2
5 changed files with 32 additions and 23 deletions
+2
View File
@@ -53,6 +53,7 @@ type indexPage struct {
// field wants is "never", what the list wants is "unlimited".
ExpiryHint string
AbsBase string
Source string // the repository this build came from, "" to say nothing
AllowVanity bool
MaxSizeBytes int64 // 0 when unlimited; the script checks against it
Stale bool // a login whose token no longer exists
@@ -83,6 +84,7 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
DefaultExpiry: config.FormatLifetime(lim.DefaultExpiry),
ExpiryHint: config.FormatDuration(lim.DefaultExpiry),
AbsBase: s.absBase(r),
Source: s.cfg.SourceURL,
AllowVanity: lim.AllowVanity,
MaxSizeBytes: lim.MaxSize,
Stale: stale,
+1 -4
View File
@@ -241,9 +241,6 @@ type page struct {
// case the markup carries no link rather than one that 404s.
Favicon string
// Source is where the footer links; empty means no footer.
Source string
// Wide widens the page for content that is a table rather than a form.
// The reading measure that suits the upload page is far too narrow for a
// listing, which otherwise ends up behind a horizontal scrollbar.
@@ -253,7 +250,7 @@ type page struct {
// page builds the common fields, resolving the session so the header can show
// who is logged in and offer only the links they can use.
func (s *Server) page(r *http.Request, title string, script bool) page {
p := page{Base: s.cfg.BasePath, Title: title, Script: script, Source: s.cfg.SourceURL}
p := page{Base: s.cfg.BasePath, Title: title, Script: script}
if s.favicon != "" {
p.Favicon = s.cfg.BasePath + "static/" + s.favicon
}
+20 -18
View File
@@ -1148,33 +1148,35 @@ func TestNoFaviconMeansNoLink(t *testing.T) {
// --- the footer ------------------------------------------------------------
// The footer names where the source lives, and an instance that would rather
// not say so can drop it. A fork gets to point at its own.
// The upload page says where the source is; no other page does, and an
// instance that would rather not say so drops it there too.
func TestSourceLinkIsOptional(t *testing.T) {
body := func(h *harness, path string) string {
t.Helper()
resp := h.get(t, path, "")
raw, _ := io.ReadAll(resp.Body)
resp.Body.Close()
return string(raw)
}
shown := newHarness(t, nil)
resp := shown.get(t, "/", "")
page, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if !strings.Contains(string(page), `<footer><a href="https://git.uncensored.hu/thayol/uncensored-send">Source</a>`) {
t.Error("the default build does not link its source")
if !strings.Contains(body(shown, "/"), `<a href="https://git.uncensored.hu/thayol/uncensored-send">`) {
t.Error("the upload page does not link its source")
}
for _, path := range []string{"/login", "/files"} {
if strings.Contains(body(shown, path), "git.uncensored.hu") {
t.Errorf("GET %s carries the source link, which belongs on the upload page alone", path)
}
}
forked := newHarness(t, func(c *config.Config) { c.SourceURL = "https://example.org/me/fork" })
resp = forked.get(t, "/login", "")
page, _ = io.ReadAll(resp.Body)
resp.Body.Close()
if !strings.Contains(string(page), `href="https://example.org/me/fork"`) {
if !strings.Contains(body(forked, "/"), `href="https://example.org/me/fork"`) {
t.Error("a fork's own source URL is not used")
}
quiet := newHarness(t, func(c *config.Config) { c.SourceURL = "" })
for _, path := range []string{"/", "/login", "/files"} {
resp := quiet.get(t, path, "")
page, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if strings.Contains(string(page), "<footer>") {
t.Errorf("GET %s still carries a footer with the source link switched off", path)
}
if page := body(quiet, "/"); strings.Contains(page, ">Source<") || strings.Contains(page, "git.uncensored.hu") {
t.Error("the upload page still names a source with the link switched off")
}
}
+9
View File
@@ -76,4 +76,13 @@
-H 'Expiry: 3d' \
{{.AbsBase}}upload</code></pre>
</section>
{{if .Source}}
<section class="card">
<h2>Source</h2>
<p class="hint">
The code this service runs is at <a href="{{.Source}}">{{.Source}}</a>.
</p>
</section>
{{end}}
{{end}}
-1
View File
@@ -26,7 +26,6 @@
<main>
{{template "content" .}}
</main>
{{if .Source}}<footer><a href="{{.Source}}">Source</a></footer>{{end}}
{{if .Script}}<script src="{{.Base}}static/app.js" defer></script>{{end}}
</body>
</html>{{end}}