serve robots.txt and sitemap.xml
Two exact paths a crawler asks for by name, so they are mux entries rather than resolver cases — no bundle can collide, since a key always sits under a section. robots.txt at the site root is served verbatim, because a site that ships one has said something deliberate; otherwise the engine emits the minimum that is true and points at the sitemap. The sitemap lists every bundle in every language it exists in, since each variant is separately reachable, with lastmod only where a bundle has a date. Every URL comes from content.URL like every other path the engine emits, so a sitemap cannot disagree with what is actually served. Both need a declared base. Without one the sitemap answers 404 rather than listing paths no crawler can resolve, and robots omits the Sitemap line rather than writing a relative one. write() was setting text/html for every caller, and headers only go out with the first byte — so a handler setting its own type would have had it silently replaced, which is how a sitemap gets served as a web page. It now splits into write and writeAs, and the tests assert the content types rather than only the bodies.
This commit is contained in:
@@ -265,6 +265,20 @@ func (b Bundle) Section() string {
|
||||
return sec
|
||||
}
|
||||
|
||||
// Everything lists every variant of every bundle, sorted by key then language.
|
||||
//
|
||||
// Every *variant*, unlike a Query, which answers with one variant per key: a sitemap lists each language as
|
||||
// its own URL, because each is separately reachable.
|
||||
func (s *Site) Everything() []Bundle {
|
||||
out := make([]Bundle, 0, len(s.byKeyLang))
|
||||
for _, key := range s.keys() {
|
||||
for _, lang := range s.Variants(key) {
|
||||
out = append(out, s.byKeyLang[key+"\x00"+lang])
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Sections lists every section that holds at least one bundle, sorted.
|
||||
func (s *Site) Sections() []string {
|
||||
seen := map[string]bool{}
|
||||
|
||||
Reference in New Issue
Block a user