From 31479ff23bf36c35bd4f5e7fdd188a144742c491 Mon Sep 17 00:00:00 2001 From: cmal Date: Thu, 9 Aug 2018 11:58:09 +0200 Subject: [PATCH] Remove condition that's always true (optimization) --- components/content/src/section.rs | 42 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/components/content/src/section.rs b/components/content/src/section.rs index 7372741..6426eb9 100644 --- a/components/content/src/section.rs +++ b/components/content/src/section.rs @@ -84,30 +84,26 @@ impl Section { let content = read_file(path)?; let mut section = Section::parse(path, &content, config)?; - if section.file.name == "_index" { - let parent_dir = path.parent().unwrap(); - let assets = find_related_assets(parent_dir); - - if let Some(ref globset) = config.ignored_content_globset { - // `find_related_assets` only scans the immediate directory (it is not recursive) so our - // filtering only needs to work against the file_name component, not the full suffix. If - // `find_related_assets` was changed to also return files in subdirectories, we could - // use `PathBuf.strip_prefix` to remove the parent directory and then glob-filter - // against the remaining path. Note that the current behaviour effectively means that - // the `ignored_content` setting in the config file is limited to single-file glob - // patterns (no "**" patterns). - section.assets = assets.into_iter() - .filter(|path| - match path.file_name() { - None => true, - Some(file) => !globset.is_match(file) - } - ).collect(); - } else { - section.assets = assets; - } + let parent_dir = path.parent().unwrap(); + let assets = find_related_assets(parent_dir); + + if let Some(ref globset) = config.ignored_content_globset { + // `find_related_assets` only scans the immediate directory (it is not recursive) so our + // filtering only needs to work against the file_name component, not the full suffix. If + // `find_related_assets` was changed to also return files in subdirectories, we could + // use `PathBuf.strip_prefix` to remove the parent directory and then glob-filter + // against the remaining path. Note that the current behaviour effectively means that + // the `ignored_content` setting in the config file is limited to single-file glob + // patterns (no "**" patterns). + section.assets = assets.into_iter() + .filter(|path| + match path.file_name() { + None => true, + Some(file) => !globset.is_match(file) + } + ).collect(); } else { - section.assets = vec![]; + section.assets = assets; } Ok(section)