Repository navigation
Serve a sitemap of each site's pages and images, and a robots.txt that points to it - #24
Conversation
…t points to it A site now serves /sitemap.xml, listing its home page, its sections and its published articles with when each last changed, and the images each article shows using the image sitemap extension. Its robots.txt lets crawlers have everything and names the sitemap. Previews serve neither.
| sections, err := models.LoadSections(ctx, rt.DB, sc.Site.Source.ID) | ||
| if err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
Performance: this is an unauthenticated endpoint. Every hit loads the body of every readable article and HTML-parses each one. Cache-Control: max-age=300 only helps clients that respect it; anything else can request it repeatedly and cost DB load and CPU in proportion to the site's size. Two options:
- Cache the generated XML in-process per site for a few minutes.
- Select only what's needed: the image
srcs can't come from SQL, butbody_htmlcould be fetched without the other columns.
Also, there's no guard for the sitemaps.org limits (50,000 URLs / 50MB uncompressed). That's probably fine for help sites, but it's worth a comment.
There was a problem hiding this comment.
Left as is. That's two queries and an HTML parse of each body, about what a busy page already costs (an article page loads every link target on the site). An in-process cache would also go stale across instances until it expired. Help sites are orders of magnitude below the 50,000 URL / 50MB limits.
🤖 Addressed by Claude Code
|
Review summary The approach is solid. The sitemap takes two queries regardless of site size, images are resolved the same way the article page renders them, and the root-file routes are registered ahead of the section pattern. Tests cover drafts, image deduplication, relative and absolute image URLs, non-http image sources, preview 404s and the no-trailing-slash behaviour. I left three inline comments:
Test gaps (minor):
🤖 Generated with Claude Code |
…and test its images directly
Helps search engines find every page of a help site, and the images its articles show.
GET /sitemap.xmllists the site's home page, each section and each published article as absolute URLs on the host and scheme the site was reached on, in the sitemaps.org format. Sections and articles carry a<lastmod>- an article's is when it was last modified, a section's the latest of its own and its articles', since its page lists them.srcof each<img>, found with an HTML parser after uploaded images are resolved to where storage serves them (exactly as the article's page renders them), resolved against the article's address, each listed once in the order they appear. Fragments are dropped, since they're never part of what's fetched.GET /robots.txtallows everything and names the sitemap.LoadReadablefor every readable article with its body.