From 3b2164b306326c79af68123a945b2c74a500f4e4 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 19 Apr 2022 23:35:42 -0700 Subject: refactor(modules): move remarks to modules module --- src/main.rs | 24 +----------------------- src/modules/mod.rs | 1 + src/modules/remarks.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 src/modules/remarks.rs diff --git a/src/main.rs b/src/main.rs index accffe9..7eb6a31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,29 +156,7 @@ async fn main() -> Result<(), Box> { router.attach_stateless(modules::sitemap::module); router.attach_stateless(modules::search::module); - - track_mount( - &mut router, - "/remarks", - "Fuwn's remarks", - Box::new(|context| { - let remarks: Vec = - serde_json::from_str(include_str!("../content/json/remarks.json")) - .unwrap(); - - success!( - format!( - "# REMARKS\n\n{}", - remarks - .iter() - .map(|r| format!("* {}", r)) - .collect::>() - .join("\n") - ), - context - ) - }), - ); + router.attach_stateless(modules::remarks::module); info!( "preliminary mounts took {}ms", diff --git a/src/modules/mod.rs b/src/modules/mod.rs index d59d62c..a41bf2b 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -17,5 +17,6 @@ // SPDX-License-Identifier: GPL-3.0-only pub mod multi_blog; +pub mod remarks; pub mod search; pub mod sitemap; diff --git a/src/modules/remarks.rs b/src/modules/remarks.rs new file mode 100644 index 0000000..83be334 --- /dev/null +++ b/src/modules/remarks.rs @@ -0,0 +1,44 @@ +// This file is part of Locus . +// Copyright (C) 2022-2022 Fuwn +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Copyright (C) 2022-2022 Fuwn +// SPDX-License-Identifier: GPL-3.0-only + +use std::lazy::SyncLazy; + +pub static REMARKS: SyncLazy> = SyncLazy::new(|| { + serde_json::from_str(include_str!("../../content/json/remarks.json")).unwrap() +}); + +pub fn module(router: &mut windmark::Router) { + crate::route::track_mount( + router, + "/remarks", + "Fuwn's remarks", + Box::new(|context| { + crate::success!( + format!( + "# REMARKS\n\n{}", + REMARKS + .iter() + .map(|r| format!("* {}", r)) + .collect::>() + .join("\n") + ), + context + ) + }), + ); +} -- cgit v1.2.3