···5454 slog.ErrorContext(r.Context(), "failed to read sitemap urls", "error", err)
5555 return
5656 }
5757- entries := make([]urlEntry, 0, len(hashes))
5757+ entries := make([]urlEntry, 0, len(hashes)+1)
5858+ entries = append(entries, urlEntry{Loc: domain + "/about"})
58595960 //this is going to get too big. at some point we need a real db to find latest
6061 //or we track new entries and expire a lsit.
+19-8
internal/sitemap/sitemap_test.go
···5252 t.Fatalf("expected valid XML sitemap, got error: %v\nbody: %s", err, rr.Body.String())
5353 }
54545555- if len(parsed.URLs) != len(hashes) {
5656- t.Fatalf("expected %d sitemap urls, got %d", len(hashes), len(parsed.URLs))
5555+ expectedCount := len(hashes) + 1 // recipe URLs + static about page
5656+ if len(parsed.URLs) != expectedCount {
5757+ t.Fatalf("expected %d sitemap urls, got %d", expectedCount, len(parsed.URLs))
5858+ }
5959+6060+ if !containsSitemapURL(parsed.URLs, "https://careme.cooking/about") {
6161+ t.Fatalf("missing expected static URL %q in sitemap body: %s", "https://careme.cooking/about", rr.Body.String())
5762 }
58635964 for _, hash := range hashes {
···8893 if err := xml.Unmarshal(rr.Body.Bytes(), &parsed); err != nil {
8994 t.Fatalf("expected valid XML sitemap, got error: %v\nbody: %s", err, rr.Body.String())
9095 }
9191- if len(parsed.URLs) != 1 {
9292- t.Fatalf("expected one URL, got %d", len(parsed.URLs))
9696+ if len(parsed.URLs) != 2 {
9797+ t.Fatalf("expected two URLs (about + recipe), got %d", len(parsed.URLs))
9898+ }
9999+ if !containsSitemapURL(parsed.URLs, "https://careme.cooking/about") {
100100+ t.Fatalf("missing expected static URL %q in sitemap body: %s", "https://careme.cooking/about", rr.Body.String())
93101 }
94102 wantURL := "https://careme.cooking/recipes?h=" + hash
9595- if parsed.URLs[0].Loc != wantURL {
9696- t.Fatalf("expected URL %q, got %q", wantURL, parsed.URLs[0].Loc)
103103+ if !containsSitemapURL(parsed.URLs, wantURL) {
104104+ t.Fatalf("missing expected URL %q in sitemap body: %s", wantURL, rr.Body.String())
97105 }
98106}
99107···121129 if err := xml.Unmarshal(rr.Body.Bytes(), &parsed); err != nil {
122130 t.Fatalf("expected valid XML sitemap, got error: %v\nbody: %s", err, rr.Body.String())
123131 }
124124- if len(parsed.URLs) != 0 {
125125- t.Fatalf("expected no URLs from non-shoppinglist keys, got %d", len(parsed.URLs))
132132+ if len(parsed.URLs) != 1 {
133133+ t.Fatalf("expected one URL (about) with no shoppinglist keys, got %d", len(parsed.URLs))
134134+ }
135135+ if parsed.URLs[0].Loc != "https://careme.cooking/about" {
136136+ t.Fatalf("expected only URL %q, got %q", "https://careme.cooking/about", parsed.URLs[0].Loc)
126137 }
127138}
128139