diff options
| author | Fuwn <[email protected]> | 2022-08-21 08:02:14 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-08-21 08:02:14 -0700 |
| commit | c8c8e0e9c40601fb57294873c27c1ab8c3fbd9be (patch) | |
| tree | 8af4a7e235e354e05dff242525f8fc8e34537d2c /src/modules | |
| parent | feat(news): add 2022. 08. 20. entry (diff) | |
| download | locus-c8c8e0e9c40601fb57294873c27c1ab8c3fbd9be.tar.xz locus-c8c8e0e9c40601fb57294873c27c1ab8c3fbd9be.zip | |
refactor(blog): macro-ify header
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(), )) |