feat(seo): metadata, previews and sitemaps for status pages and the app
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m23s
ci / test (pull_request) Successful in 12m44s
ci / build (pull_request) Successful in 16m9s
ci / image (pull_request) Successful in 3m24s

Status pages describe themselves to search engines and link previews:
description (from the page's text, else its status), canonical address,
language versions via ?lang= with hreflang and x-default, Open Graph and
Twitter tags, and a 1200x630 preview image per page and language showing
its name and current status (/og.png). Each page has a sitemap.xml, and
robots.txt keeps crawlers off feeds, the API and subscription forms.
Component, legal and subscription pages are noindex.

In the cloud edition the app's sign-in, sign-up and legal pages get the
same tags with a preview image of their own, plus robots.txt and a
sitemap. Everything signed in stays noindex, and self-hosted
installations keep the whole app out of search engines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-28 22:50:34 +01:00
1 parent 918c71f283
commit 3baeb98ee2
23 files changed
+1546 -129

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
package api_test
import (
"bytes"
"io"
"net/http"
"strings"
"testing"
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
)
func (b *browser) raw(path string) (int, http.Header, []byte) {
b.t.Helper()
resp, err := b.hc.Get(b.base + path)
if err != nil {
b.t.Fatalf("GET %s failed: %v", path, err)
}
defer func() { _ = resp.Body.Close() }()
body, _ := io.ReadAll(resp.Body)
return resp.StatusCode, resp.Header, body
}
func TestPublicPagesForSearchEngines(t *testing.T) {
const publicURL = "https://app.example.test"
cloud := newEnvWith(t, func(c *config.API) {
c.Edition, c.SignupVerify, c.PublicURL = config.EditionCloud, "off", publicURL
})
b := cloud.browser(t)
_, _, html := b.page("/login?next=/monitors&lang=de")
for _, want := range []string{
`<link rel="canonical" href="` + publicURL + `/login?lang=de">`,
`<link rel="alternate" hreflang="en" href="` + publicURL + `/login?lang=en">`,
`<link rel="alternate" hreflang="x-default" href="` + publicURL + `/login">`,
`<meta property="og:image" content="` + publicURL + `/og.png?lang=de">`,
`<meta name="description" content="UptimeSebi überwacht`,
`<html lang="de">`,
} {
if !strings.Contains(html, want) {
t.Errorf("login page lacks %s", want)
}
}
if strings.Contains(html, "noindex") {
t.Errorf("login page is noindex in the cloud edition")
}
if _, _, html := b.page("/signup"); !strings.Contains(html, `<link rel="canonical" href="`+publicURL+`/signup">`) {
t.Errorf("signup page lacks its canonical address")
}
_, _, robots := b.raw("/robots.txt")
if !strings.Contains(string(robots), "Allow: /login\n") || !strings.Contains(string(robots), "Disallow: /\n") || !strings.Contains(string(robots), "Sitemap: "+publicURL+"/sitemap.xml") {
t.Errorf("robots.txt = %q", robots)
}
code, _, sm := b.raw("/sitemap.xml")
if code != http.StatusOK || !strings.Contains(string(sm), "<loc>"+publicURL+"/signup</loc>") || !strings.Contains(string(sm), `hreflang="de" href="`+publicURL+`/login?lang=de"`) {
t.Errorf("sitemap = %d %s", code, sm)
}
code, h, png := b.raw("/og.png?lang=en")
if code != http.StatusOK || h.Get("Content-Type") != "image/png" || !bytes.HasPrefix(png, []byte("\x89PNG")) {
t.Errorf("preview image = %d %s", code, h.Get("Content-Type"))
}
// Signed in, the console stays out of search engines.
b.signup("seo@"+uniq("seo")+".test", uniq("seo-"))
if _, _, html := b.page("/"); !strings.Contains(html, `<meta name="robots" content="noindex, nofollow">`) || strings.Contains(html, "og:title") {
t.Errorf("console page is indexable")
}
// Self-hosted installations keep everything out.
self := newEnv(t).browser(t)
if _, _, html := self.page("/login"); !strings.Contains(html, "noindex") || strings.Contains(html, "canonical") {
t.Errorf("self-hosted login page is indexable")
}
if _, _, robots := self.raw("/robots.txt"); string(robots) != "User-agent: *\nDisallow: /\n" {
t.Errorf("self-hosted robots.txt = %q", robots)
}
if code, _, _ := self.raw("/sitemap.xml"); code != http.StatusNotFound {
t.Errorf("self-hosted sitemap = %d, want 404", code)
}
}