aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/archiver/mod.rs35
-rw-r--r--src/command/generate.rs14
-rw-r--r--src/template.rs27
3 files changed, 35 insertions, 41 deletions
diff --git a/src/archiver/mod.rs b/src/archiver/mod.rs
index a0655a4..b83f2ef 100644
--- a/src/archiver/mod.rs
+++ b/src/archiver/mod.rs
@@ -74,26 +74,21 @@ fn read_archive(archive_directory: &PathBuf) -> Vec<ArchiveEntry> {
for entry in entries.filter_map(Result::ok) {
let entry_path = entry.path();
let post_id = entry.file_name();
- if let Ok(entry_type) = entry.file_type() {
- if entry_type.is_dir() {
- if let Ok(candidates) = read_dir(&entry_path) {
- for candidate in candidates.filter_map(Result::ok) {
- let candidate_path = candidate.path();
- if let Some(extension) = candidate_path.extension() {
- if extension == "gmi" {
- if let Some(slug) = candidate_path.file_stem() {
- if let (Some(post_id), Some(slug)) =
- (post_id.to_str(), slug.to_str())
- {
- archive_entries.push(ArchiveEntry {
- id: post_id.to_string(),
- slug: slug.to_string(),
- });
- }
- }
- }
- }
- }
+ if let Ok(entry_type) = entry.file_type()
+ && entry_type.is_dir()
+ && let Ok(candidates) = read_dir(&entry_path)
+ {
+ for candidate in candidates.filter_map(Result::ok) {
+ let candidate_path = candidate.path();
+ if let Some(extension) = candidate_path.extension()
+ && extension == "gmi"
+ && let Some(slug) = candidate_path.file_stem()
+ && let (Some(post_id), Some(slug)) = (post_id.to_str(), slug.to_str())
+ {
+ archive_entries.push(ArchiveEntry {
+ id: post_id.to_string(),
+ slug: slug.to_string(),
+ });
}
}
}
diff --git a/src/command/generate.rs b/src/command/generate.rs
index 33ea6a4..966c26b 100644
--- a/src/command/generate.rs
+++ b/src/command/generate.rs
@@ -33,13 +33,13 @@ impl Generate {
let entries = read_dir(post_path).ok()?;
for entry in entries.filter_map(Result::ok) {
let entry_path = entry.path();
- if let Some(extension) = entry_path.extension() {
- if extension == "gmi" {
- let mut file = File::open(entry_path).ok()?;
- let mut contents = String::new();
- file.read_to_string(&mut contents).ok()?;
- return Some(contents);
- }
+ if let Some(extension) = entry_path.extension()
+ && extension == "gmi"
+ {
+ let mut file = File::open(entry_path).ok()?;
+ let mut contents = String::new();
+ file.read_to_string(&mut contents).ok()?;
+ return Some(contents);
}
}
None
diff --git a/src/template.rs b/src/template.rs
index 05c5db4..00f9118 100644
--- a/src/template.rs
+++ b/src/template.rs
@@ -40,7 +40,7 @@ impl std::fmt::Display for Token {
} => {
writeln!(f, "ConditionalDirective {condition} [[[")?;
for child in children {
- writeln!(f, "\t{child}").unwrap();
+ writeln!(f, "\t{child}")?;
}
write!(f, "]]]")
}
@@ -51,7 +51,7 @@ impl std::fmt::Display for Token {
} => {
writeln!(f, "IteratorDirective {member_label} in {collection} [[[")?;
for child in children {
- writeln!(f, "\t{child}").unwrap();
+ writeln!(f, "\t{child}")?;
}
write!(f, "]]]")
}
@@ -237,18 +237,17 @@ fn tokenize(template: &str, tokens: &mut Vec<Token>) -> Result<()> {
let directive_block = &remaining_template[..closing_block];
remaining_template = &remaining_template[closing_block + 5..];
tokenize(directive_block, &mut children)?;
- if parts.len() == 2 {
- if let Some(first_part) = parts.first() {
- if let Some(second_part) = parts.get(1) {
- let collection = first_part.trim().to_string();
- let member_label = second_part.trim().to_string();
- tokens.push(Token::IteratorDirective {
- collection,
- member_label,
- children,
- });
- }
- }
+ if parts.len() == 2
+ && let Some(first_part) = parts.first()
+ && let Some(second_part) = parts.get(1)
+ {
+ let collection = first_part.trim().to_string();
+ let member_label = second_part.trim().to_string();
+ tokens.push(Token::IteratorDirective {
+ collection,
+ member_label,
+ children,
+ });
}
}
}