about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLoïc BRANSTETT <lolo.branstett@numericable.fr>2022-03-09 11:18:28 +0100
committerLoïc BRANSTETT <lolo.branstett@numericable.fr>2022-03-09 13:45:50 +0100
commite346920907d1dec22d2dcc19b0dc483b9a94810b (patch)
tree6cafc0327b24b44b53e8d68d57f5e96159c90049
parent4e067e80ebb60022d6446335b0721feed73483b9 (diff)
Also take in account mdbook redirect in linkchecker
-rw-r--r--src/tools/linkchecker/main.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs
index 46daaf42883..c9b1649200d 100644
--- a/src/tools/linkchecker/main.rs
+++ b/src/tools/linkchecker/main.rs
@@ -489,16 +489,22 @@ fn is_exception(file: &Path, link: &str) -> bool {
 /// If the given HTML file contents is an HTML redirect, this returns the
 /// destination path given in the redirect.
 fn maybe_redirect(source: &str) -> Option<String> {
-    const REDIRECT: &str = "<p>Redirecting to <a href=";
+    const REDIRECT_RUSTDOC: (usize, &str) = (7, "<p>Redirecting to <a href=");
+    const REDIRECT_MDBOOK: (usize, &str) = (8 - 7, "<p>Redirecting to... <a href=");
 
     let mut lines = source.lines();
-    let redirect_line = lines.nth(7)?;
 
-    redirect_line.find(REDIRECT).map(|i| {
-        let rest = &redirect_line[(i + REDIRECT.len() + 1)..];
-        let pos_quote = rest.find('"').unwrap();
-        rest[..pos_quote].to_owned()
-    })
+    let mut find_redirect = |(line_rel, redirect_pattern): (usize, &str)| {
+        let redirect_line = lines.nth(line_rel)?;
+
+        redirect_line.find(redirect_pattern).map(|i| {
+            let rest = &redirect_line[(i + redirect_pattern.len() + 1)..];
+            let pos_quote = rest.find('"').unwrap();
+            rest[..pos_quote].to_owned()
+        })
+    };
+
+    find_redirect(REDIRECT_RUSTDOC).or_else(|| find_redirect(REDIRECT_MDBOOK))
 }
 
 fn with_attrs_in_source<F: FnMut(&str, usize, &str)>(source: &str, attr: &str, mut f: F) {