Skip to content

Commit

Permalink
Also take in account mdbook redirect in linkchecker
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Mar 9, 2022
1 parent 4e067e8 commit e346920
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/tools/linkchecker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e346920

Please sign in to comment.