Skip to content

Commit

Permalink
Moved fragment check into it's own function.
Browse files Browse the repository at this point in the history
  • Loading branch information
HU90m committed Jul 12, 2023
1 parent 508f26e commit a28ae68
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lychee-lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
clippy::default_trait_access,
clippy::used_underscore_binding
)]
use std::path::Path;
use std::{collections::HashSet, time::Duration};
use tokio::fs::File;
use tokio::io::AsyncReadExt;
Expand Down Expand Up @@ -667,11 +668,20 @@ impl Client {
if !path.exists() {
return ErrorKind::InvalidFilePath(uri.clone()).into();
}
if self.include_fragments {
Self::check_fragment(&path, uri).await
} else {
Status::Ok(StatusCode::OK)
}
}

/// Checks a `file` URI's fragment.
pub async fn check_fragment(path: &Path, uri: &Uri) -> Status {
let is_md = path
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("md"));

if let (true, Some(frag), true) = (is_md, uri.url.fragment(), self.include_fragments) {
if let (true, Some(frag)) = (is_md, uri.url.fragment()) {
let mut content = String::new();
File::open(path)
.await
Expand Down

0 comments on commit a28ae68

Please sign in to comment.