Skip to content

Commit 05c3aec

Browse files
Nemo157Joshua Nelson
authored and
Joshua Nelson
committed
Don't move the sitemap
1 parent f090d09 commit 05c3aec

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/web/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ mod tests {
130130
),
131131
("/releases/recent/1", "/releases/recent/:page"),
132132
("/-/static/robots.txt", "static resource"),
133-
("/-/sitemap.xml", "static resource"),
133+
("/sitemap.xml", "static resource"),
134134
("/-/static/style.css", "static resource"),
135135
("/-/static/vendored.css", "static resource"),
136136
("/rustdoc/rcc/0.0.0/rcc/index.html", "database"),

src/web/routes.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ pub(super) const DOC_RUST_LANG_ORG_REDIRECTS: &[&str] =
1010
pub(super) fn build_routes() -> Routes {
1111
let mut routes = Routes::new();
1212

13+
// Well known resources, robots.txt and favicon.ico support redirection, the sitemap.xml
14+
// must live at the site root:
15+
// https://developers.google.com/search/reference/robots_txt#handling-http-result-codes
16+
// https://support.google.com/webmasters/answer/183668?hl=en
1317
routes.static_resource("/robots.txt", PermanentRedirect("/-/static/robots.txt"));
1418
routes.static_resource("/favicon.ico", PermanentRedirect("/-/static/favicon.ico"));
19+
routes.static_resource("/sitemap.xml", super::sitemap::sitemap_handler);
1520

16-
// These should not need to be served from the root as we reference the inner path in links,
21+
// This should not need to be served from the root as we reference the inner path in links,
1722
// but clients might have cached the url and need to update it.
1823
routes.static_resource(
1924
"/opensearch.xml",
2025
PermanentRedirect("/-/static/opensearch.xml"),
2126
);
22-
routes.static_resource("/sitemap.xml", PermanentRedirect("/-/sitemap.xml"));
2327

24-
routes.static_resource("/-/sitemap.xml", super::sitemap::sitemap_handler);
2528
routes.static_resource("/-/static/:file", super::statics::static_handler);
2629

2730
routes.internal_page("/", super::releases::home_page);
@@ -330,19 +333,19 @@ mod tests {
330333
#[test]
331334
fn test_root_redirects() {
332335
wrapper(|env| {
333-
// These are "well-known" resources that must be served from the root
336+
// These are "well-known" resources that will be requested from the root, but support
337+
// redirection
334338
assert_redirect("/favicon.ico", "/-/static/favicon.ico", env.frontend())?;
335339
assert_redirect("/robots.txt", "/-/static/robots.txt", env.frontend())?;
336340

337-
// These have previously been served with a url pointing to the root, it may be
341+
// This has previously been served with a url pointing to the root, it may be
338342
// plausible to remove the redirects in the future, but for now we need to keep serving
339-
// them.
343+
// it.
340344
assert_redirect(
341345
"/opensearch.xml",
342346
"/-/static/opensearch.xml",
343347
env.frontend(),
344348
)?;
345-
assert_redirect("/sitemap.xml", "/-/sitemap.xml", env.frontend())?;
346349

347350
Ok(())
348351
});

static/robots.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Sitemap: https://docs.rs/-/sitemap.xml
1+
Sitemap: https://docs.rs/sitemap.xml

0 commit comments

Comments
 (0)