From c96318553c1d3650f0b1cce2db0af7f41f697e62 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 16 Apr 2023 21:16:53 -0700 Subject: refactor(macros): move unnecessary crate-level macros --- src/modules/static.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/modules') 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 // 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!( -- cgit v1.2.3