Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8e5b8dc

Browse files
add --extra-target to tell linkchecker more places to find link targets
1 parent 4aaebcb commit 8e5b8dc

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

‎src/tools/linkchecker/main.rs‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use html5ever::tendril::ByteTendril;
2929
use html5ever::tokenizer::{
3030
BufferQueue, TagToken, Token, TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts,
3131
};
32+
use std::collections::hash_map::Entry;
33+
use std::iter::once;
3234

3335
// Add linkcheck exceptions here
3436
// If at all possible you should use intra-doc links to avoid linkcheck issues. These
@@ -114,13 +116,16 @@ macro_rules! t {
114116
#[derive(Parser)]
115117
struct Cli {
116118
docs: PathBuf,
119+
#[clap(long)]
120+
extra_target: Vec<PathBuf>,
117121
}
118122

119123
fn main() {
120124
let mut cli = Cli::parse();
121125
cli.docs = cli.docs.canonicalize().unwrap();
122126

123-
let mut checker = Checker { root: cli.docs.clone(), cache: HashMap::new() };
127+
let mut checker =
128+
Checker { root: cli.docs.clone(), extra_targets: cli.extra_target, cache: HashMap::new() };
124129
let mut report = Report {
125130
errors: 0,
126131
start: Instant::now(),
@@ -142,6 +147,7 @@ fn main() {
142147

143148
struct Checker {
144149
root: PathBuf,
150+
extra_targets: Vec<PathBuf>,
145151
cache: Cache,
146152
}
147153

@@ -434,15 +440,24 @@ impl Checker {
434440
let pretty_path =
435441
file.strip_prefix(&self.root).unwrap_or(file).to_str().unwrap().to_string();
436442

437-
let entry =
438-
self.cache.entry(pretty_path.clone()).or_insert_with(|| match fs::metadata(file) {
443+
for base in once(&self.root).chain(self.extra_targets.iter()) {
444+
// TODO: rebase and turn into a let else
445+
let entry = self.cache.entry(pretty_path.clone());
446+
if let Entry::Occupied(e) = &entry {
447+
if !matches!(e.get(), FileEntry::Missing) {
448+
break;
449+
}
450+
}
451+
452+
let file = base.join(&pretty_path);
453+
entry.insert_entry(match fs::metadata(&file) {
439454
Ok(metadata) if metadata.is_dir() => FileEntry::Dir,
440455
Ok(_) => {
441456
if file.extension().and_then(|s| s.to_str()) != Some("html") {
442457
FileEntry::OtherFile
443458
} else {
444459
report.html_files += 1;
445-
load_html_file(file, report)
460+
load_html_file(&file, report)
446461
}
447462
}
448463
Err(e) if e.kind() == ErrorKind::NotFound => FileEntry::Missing,
@@ -458,6 +473,9 @@ impl Checker {
458473
panic!("unexpected read error for {}: {}", file.display(), e);
459474
}
460475
});
476+
}
477+
478+
let entry = self.cache.get(&pretty_path).unwrap();
461479
(pretty_path, entry)
462480
}
463481
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /