diff options
| author | Fuwn <[email protected]> | 2022-04-14 19:10:37 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-04-14 19:10:37 -0700 |
| commit | 822684a50b633000f3009b8b9d38418954afff2d (patch) | |
| tree | faee681c4cc6fc9328477a5a011e8e5303d85228 /src | |
| parent | feat(uptime): more options (diff) | |
| download | locus-822684a50b633000f3009b8b9d38418954afff2d.tar.xz locus-822684a50b633000f3009b8b9d38418954afff2d.zip | |
refactor(macros): use success! in mount_page!
Diffstat (limited to 'src')
| -rw-r--r-- | src/macros.rs | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/src/macros.rs b/src/macros.rs index fe1f20b..ae0fb4e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -17,6 +17,22 @@ // SPDX-License-Identifier: GPL-3.0-only #[macro_export] +macro_rules! success { + ($body:expr, $context:ident) => { + Response::Success( + Main { + body: &$body, + hits: &crate::hits_from_route($context.url.path()), + quote: QUOTES.choose(&mut rand::thread_rng()).unwrap(), + commit: &format!("/tree/{}", env!("VERGEN_GIT_SHA")), + mini_commit: env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"), + } + .to_string(), + ) + }; +} + +#[macro_export] macro_rules! mount_page { ($router:ident, $at:literal, $description:literal, $file:literal) => { (*crate::ROUTES.lock().unwrap()) @@ -25,20 +41,9 @@ macro_rules! mount_page { ($router).mount( $at, Box::new(|context| { - Response::Success( - Main { - body: include_str!(concat!( - "../content/pages/", - $file, - ".gmi" - )) - .into(), - hits: &crate::hits_from_route(context.url.path()), - quote: QUOTES.choose(&mut rand::thread_rng()).unwrap(), - commit: &format!("/tree/{}", env!("VERGEN_GIT_SHA")), - mini_commit: env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"), - } - .to_string(), + success!( + include_str!(concat!("../content/pages/", $file, ".gmi")), + context ) }), ); @@ -62,19 +67,3 @@ macro_rules! mount_file { ); }; } - -#[macro_export] -macro_rules! success { - ($body:expr, $context:ident) => { - Response::Success( - Main { - body: &$body, - hits: &crate::hits_from_route($context.url.path()), - quote: QUOTES.choose(&mut rand::thread_rng()).unwrap(), - commit: &format!("/tree/{}", env!("VERGEN_GIT_SHA")), - mini_commit: env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"), - } - .to_string(), - ) - }; -} |