diff options
| author | Fuwn <[email protected]> | 2023-04-16 21:16:53 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-16 21:16:53 -0700 |
| commit | c96318553c1d3650f0b1cce2db0af7f41f697e62 (patch) | |
| tree | 34445a4609f8b2d02a5ba3e9d78761750fb24786 /src/modules | |
| parent | refactor(response): rewrite unnecessary macro to function (diff) | |
| download | locus-c96318553c1d3650f0b1cce2db0af7f41f697e62.tar.xz locus-c96318553c1d3650f0b1cce2db0af7f41f697e62.zip | |
refactor(macros): move unnecessary crate-level macros
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/static.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/modules/static.rs b/src/modules/static.rs index d2535df..c451d76 100644 --- a/src/modules/static.rs +++ b/src/modules/static.rs @@ -16,7 +16,37 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use crate::batch_mount; +macro_rules! batch_mount { + ("pages", $router:ident, $(($path:literal, $description:literal, $file:literal)),* $(,)?) => { + $( + (*$crate::route::ROUTES.lock().unwrap()) + .insert($path.to_string(), $crate::route::Route::new($description)); + + ($router).mount($path, |context: ::windmark::context::RouteContext| { + let content = + include_str!(concat!("../../content/static/", $file, ".gmi")); + + $crate::route::cache(&context, &content); + $crate::response::success(&content, &context) + }); + )* + }; + ("files", $router:ident, $(($path:literal, $description:literal, $file:literal)),* $(,)?) => { + $( + (*$crate::route::ROUTES.lock().unwrap()) + .insert($path.to_string(), $crate::route::Route::new($description)); + + ($router).mount( + $path, + ::windmark::binary_success_auto!(include_bytes!(concat!( + "../../content/meta/", + $file + ))), + ); + )* + }; +} + pub fn module(router: &mut windmark::Router) { batch_mount!( |