diff options
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(), - ) - }; -} |