diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/blog/module.rs | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/modules/blog/module.rs b/src/modules/blog/module.rs index 288f496..e2ac456 100644 --- a/src/modules/blog/module.rs +++ b/src/modules/blog/module.rs @@ -346,30 +346,24 @@ fn construct_header( return Err(()); }; + macro_rules! field { + ($getter:ident, $format:literal) => { + if post.$getter().is_some() { + format!($format, post.$getter().clone().unwrap()) + } else { + "".to_string() + } + }; + } + Ok(( format!( "# {}\n\n{}{}{}{}", post.name().clone().unwrap_or_else(|| name.to_string()), - if post.author().is_some() { - format!("Author: {}\n", post.author().clone().unwrap()) - } else { - "".to_string() - }, - if post.created().is_some() { - format!("Created: {}\n", post.created().clone().unwrap()) - } else { - "".to_string() - }, - if post.last_modified().is_some() { - format!("Last Modified: {}\n", post.last_modified().clone().unwrap()) - } else { - "".to_string() - }, - if post.description().is_some() { - format!("\n{}\n", post.description().clone().unwrap()) - } else { - "".to_string() - }, + field!(author, "Author: {}\n"), + field!(created, "Created: {}\n"), + field!(last_modified, "Last Modified: {}\n"), + field!(description, "\n{}\n"), ), post.description().clone().unwrap_or_default(), )) |