Fix needless_borrow warnings
This commit is contained in:
parent
02b57b942f
commit
3430d948f7
@ -57,7 +57,7 @@ impl FileInfo {
|
||||
let name = path.file_stem().unwrap().to_string_lossy().to_string();
|
||||
let canonical = parent.join(&name);
|
||||
let mut components =
|
||||
find_content_components(&file_path.strip_prefix(base_path).unwrap_or(&file_path));
|
||||
find_content_components(file_path.strip_prefix(base_path).unwrap_or(&file_path));
|
||||
let relative = if !components.is_empty() {
|
||||
format!("{}/{}.md", components.join("/"), name)
|
||||
} else {
|
||||
@ -91,7 +91,7 @@ impl FileInfo {
|
||||
let parent = path.parent().expect("Get parent of section").to_path_buf();
|
||||
let name = path.file_stem().unwrap().to_string_lossy().to_string();
|
||||
let components =
|
||||
find_content_components(&file_path.strip_prefix(base_path).unwrap_or(&file_path));
|
||||
find_content_components(file_path.strip_prefix(base_path).unwrap_or(&file_path));
|
||||
let relative = if !components.is_empty() {
|
||||
format!("{}/{}.md", components.join("/"), name)
|
||||
} else {
|
||||
|
||||
@ -295,7 +295,7 @@ impl Library {
|
||||
for (path, page) in self.pages.iter_mut() {
|
||||
let parent_filename = &index_filename_by_lang[&page.lang];
|
||||
add_translation(&page.file.canonical, path);
|
||||
let mut parent_section_path = page.file.parent.join(&parent_filename);
|
||||
let mut parent_section_path = page.file.parent.join(parent_filename);
|
||||
|
||||
while let Some(parent_section) = self.sections.get_mut(&parent_section_path) {
|
||||
let is_transparent = parent_section.meta.transparent;
|
||||
@ -323,7 +323,7 @@ impl Library {
|
||||
|
||||
// We've added `_index(.{LANG})?.md` so if we are here so we need to go up twice
|
||||
match parent_section_path.clone().parent().unwrap().parent() {
|
||||
Some(parent) => parent_section_path = parent.join(&parent_filename),
|
||||
Some(parent) => parent_section_path = parent.join(parent_filename),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,9 @@ static RFC3339_DATE: Lazy<Regex> = Lazy::new(|| {
|
||||
).unwrap()
|
||||
});
|
||||
|
||||
static FOOTNOTES_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"<sup class="footnote-reference"><a href=\s*.*?>\s*.*?</a></sup>"#).unwrap());
|
||||
static FOOTNOTES_RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r#"<sup class="footnote-reference"><a href=\s*.*?>\s*.*?</a></sup>"#).unwrap()
|
||||
});
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Page {
|
||||
@ -260,7 +262,7 @@ impl Page {
|
||||
fn serialize_assets(&self, base_path: &Path) -> Vec<String> {
|
||||
self.assets
|
||||
.iter()
|
||||
.filter_map(|asset| asset.strip_prefix(&self.file.path.parent().unwrap()).ok())
|
||||
.filter_map(|asset| asset.strip_prefix(self.file.path.parent().unwrap()).ok())
|
||||
.filter_map(|filename| filename.to_str())
|
||||
.map(|filename| {
|
||||
let mut path = self.file.path.clone();
|
||||
|
||||
@ -205,7 +205,7 @@ impl<'a> Paginator<'a> {
|
||||
} else {
|
||||
paginator.insert("next", Value::Null);
|
||||
}
|
||||
paginator.insert("number_pagers", to_value(&self.pagers.len()).unwrap());
|
||||
paginator.insert("number_pagers", to_value(self.pagers.len()).unwrap());
|
||||
let base_url = if self.paginate_path.is_empty() {
|
||||
self.permalink.to_string()
|
||||
} else {
|
||||
|
||||
@ -198,7 +198,7 @@ impl Section {
|
||||
fn serialize_assets(&self) -> Vec<String> {
|
||||
self.assets
|
||||
.iter()
|
||||
.filter_map(|asset| asset.strip_prefix(&self.file.path.parent().unwrap()).ok())
|
||||
.filter_map(|asset| asset.strip_prefix(self.file.path.parent().unwrap()).ok())
|
||||
.filter_map(|filename| filename.to_str())
|
||||
.map(|filename| format!("{}{}", self.path, filename))
|
||||
.collect()
|
||||
|
||||
@ -605,7 +605,7 @@ pub fn read_image_metadata<P: AsRef<Path>>(path: P) -> Result<ImageMetaResponse>
|
||||
|
||||
match ext.as_str() {
|
||||
"svg" => {
|
||||
let img = SvgMetadata::parse_file(&path).with_context(err_context)?;
|
||||
let img = SvgMetadata::parse_file(path).with_context(err_context)?;
|
||||
match (img.height(), img.width(), img.view_box()) {
|
||||
(Some(h), Some(w), _) => Ok((h, w)),
|
||||
(_, _, Some(view_box)) => Ok((view_box.height, view_box.width)),
|
||||
|
||||
@ -218,7 +218,7 @@ impl Site {
|
||||
// if we are processing a section we have to collect
|
||||
// index files for all languages and process them simultaneously
|
||||
// before any of the pages
|
||||
let index_files = WalkDir::new(&path)
|
||||
let index_files = WalkDir::new(path)
|
||||
.follow_links(true)
|
||||
.max_depth(1)
|
||||
.into_iter()
|
||||
@ -664,7 +664,7 @@ impl Site {
|
||||
asset_path,
|
||||
¤t_path.join(
|
||||
asset_path
|
||||
.strip_prefix(&page.file.path.parent().unwrap())
|
||||
.strip_prefix(page.file.path.parent().unwrap())
|
||||
.expect("Couldn't get filename from page asset"),
|
||||
),
|
||||
)?;
|
||||
@ -1071,7 +1071,7 @@ impl Site {
|
||||
asset_path,
|
||||
&output_path.join(
|
||||
asset_path
|
||||
.strip_prefix(§ion.file.path.parent().unwrap())
|
||||
.strip_prefix(section.file.path.parent().unwrap())
|
||||
.expect("Failed to get asset filename for section"),
|
||||
),
|
||||
)?;
|
||||
|
||||
@ -51,12 +51,12 @@ fn compile_sass_glob(
|
||||
for file in files {
|
||||
let css = compile_file(&file, options.clone()).map_err(|e| anyhow!(e))?;
|
||||
|
||||
let path_inside_sass = file.strip_prefix(&sass_path).unwrap();
|
||||
let path_inside_sass = file.strip_prefix(sass_path).unwrap();
|
||||
let parent_inside_sass = path_inside_sass.parent();
|
||||
let css_output_path = output_path.join(path_inside_sass).with_extension("css");
|
||||
|
||||
if parent_inside_sass.is_some() {
|
||||
create_dir_all(&css_output_path.parent().unwrap())?;
|
||||
create_dir_all(css_output_path.parent().unwrap())?;
|
||||
}
|
||||
|
||||
create_file(&css_output_path, &css)?;
|
||||
|
||||
@ -62,7 +62,7 @@ pub fn load_tera(path: &Path, config: &Config) -> Result<Tera> {
|
||||
|
||||
if let Some(ref theme) = config.theme {
|
||||
// Test that the templates folder exist for that theme
|
||||
let theme_path = path.join("themes").join(&theme);
|
||||
let theme_path = path.join("themes").join(theme);
|
||||
if !theme_path.join("templates").exists() {
|
||||
bail!("Theme `{}` is missing a templates folder", theme);
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ pub fn is_path_in_directory(parent: &Path, path: &Path) -> Result<bool> {
|
||||
/// Create a file with the content given
|
||||
pub fn create_file(path: &Path, content: &str) -> Result<()> {
|
||||
let mut file =
|
||||
File::create(&path).with_context(|| format!("Failed to create file {}", path.display()))?;
|
||||
File::create(path).with_context(|| format!("Failed to create file {}", path.display()))?;
|
||||
file.write_all(content.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
@ -92,19 +92,19 @@ pub fn copy_file_if_needed(src: &Path, dest: &Path, hard_link: bool) -> Result<(
|
||||
.with_context(|| format!("Failed to get metadata of {}", src.display()))?;
|
||||
let src_mtime = FileTime::from_last_modification_time(&src_metadata);
|
||||
if Path::new(&dest).is_file() {
|
||||
let target_metadata = metadata(&dest)?;
|
||||
let target_metadata = metadata(dest)?;
|
||||
let target_mtime = FileTime::from_last_modification_time(&target_metadata);
|
||||
if !(src_mtime == target_mtime && src_metadata.len() == target_metadata.len()) {
|
||||
copy(src, &dest).with_context(|| {
|
||||
copy(src, dest).with_context(|| {
|
||||
format!("Was not able to copy file {} to {}", src.display(), dest.display())
|
||||
})?;
|
||||
set_file_mtime(&dest, src_mtime)?;
|
||||
set_file_mtime(dest, src_mtime)?;
|
||||
}
|
||||
} else {
|
||||
copy(src, &dest).with_context(|| {
|
||||
copy(src, dest).with_context(|| {
|
||||
format!("Was not able to copy directory {} to {}", src.display(), dest.display())
|
||||
})?;
|
||||
set_file_mtime(&dest, src_mtime)?;
|
||||
set_file_mtime(dest, src_mtime)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@ -318,13 +318,12 @@ pub fn serve(
|
||||
Ok(a) => a,
|
||||
Err(_) => return Err(anyhow!("Invalid address: {}.", address)),
|
||||
};
|
||||
if (TcpListener::bind(&bind_address)).is_err() {
|
||||
if (TcpListener::bind(bind_address)).is_err() {
|
||||
return Err(anyhow!("Cannot start server on address {}.", address));
|
||||
}
|
||||
|
||||
let config_path = PathBuf::from(config_file);
|
||||
let config_path_rel =
|
||||
diff_paths(&config_path, &root_dir).unwrap_or_else(|| config_path.clone());
|
||||
let config_path_rel = diff_paths(&config_path, root_dir).unwrap_or_else(|| config_path.clone());
|
||||
|
||||
// An array of (path, WatchMode) where the path should be watched for changes,
|
||||
// and the WatchMode value indicates whether this file/folder must exist for
|
||||
|
||||
@ -15,12 +15,12 @@ mod prompt;
|
||||
fn get_config_file_path(dir: &Path, config_path: &Path) -> (PathBuf, PathBuf) {
|
||||
let root_dir = dir
|
||||
.ancestors()
|
||||
.find(|a| a.join(&config_path).exists())
|
||||
.find(|a| a.join(config_path).exists())
|
||||
.unwrap_or_else(|| panic!("could not find directory containing config file"));
|
||||
|
||||
// if we got here we found root_dir so config file should exist so we can unwrap safely
|
||||
let config_file = root_dir
|
||||
.join(&config_path)
|
||||
.join(config_path)
|
||||
.canonicalize()
|
||||
.unwrap_or_else(|_| panic!("could not find directory containing config file"));
|
||||
(root_dir.to_path_buf(), config_file)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user