diff options
| author | Fuwn <[email protected]> | 2022-04-19 23:24:10 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-04-19 23:24:10 -0700 |
| commit | 817688de7b5b0ae1f2d06791569dd708164cabd6 (patch) | |
| tree | aca46dbe0a90a1314354f77f212d10af7685cfea /src | |
| parent | refactor(modules): move modules to module (diff) | |
| download | locus-817688de7b5b0ae1f2d06791569dd708164cabd6.tar.xz locus-817688de7b5b0ae1f2d06791569dd708164cabd6.zip | |
refactor(modules): move sitemap to modules module
Diffstat (limited to 'src')
| -rw-r--r-- | src/macros.rs | 4 | ||||
| -rw-r--r-- | src/main.rs | 22 | ||||
| -rw-r--r-- | src/modules/mod.rs | 1 | ||||
| -rw-r--r-- | src/modules/multi_blog.rs | 6 | ||||
| -rw-r--r-- | src/modules/sitemap.rs | 38 |
5 files changed, 46 insertions, 25 deletions
diff --git a/src/macros.rs b/src/macros.rs index 7dd6048..47a85cb 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -27,8 +27,8 @@ macro_rules! success { ($body:expr, $context:ident) => {{ $crate::route::cache(&$context, &$body); - Response::Success( - Main { + windmark::Response::Success( + $crate::Main { body: &$body, hits: &$crate::route::hits_from($context.url.path()), quote: { diff --git a/src/main.rs b/src/main.rs index bb17767..c625b2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -154,24 +154,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { )) }), ); - track_mount( - &mut router, - "/sitemap", - "A map of all publicly available routes on this Gemini capsule", - Box::new(|context| { - success!( - format!( - "# SITEMAP\n\n{}", - (*ROUTES.lock().unwrap()) - .iter() - .map(|(r, d)| format!("=> {} {}", r, d.description)) - .collect::<Vec<_>>() - .join("\n") - ), - context - ) - }), - ); + + router.attach_stateless(modules::sitemap::module); track_mount( &mut router, @@ -303,7 +287,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { ); time_mount = Instant::now(); - router.attach_stateless(modules::multi_blog::multi_blog); + router.attach_stateless(modules::multi_blog::module); info!( "blog mounts took {}ms", diff --git a/src/modules/mod.rs b/src/modules/mod.rs index bab3cb1..b24e0ab 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -17,3 +17,4 @@ // SPDX-License-Identifier: GPL-3.0-only pub mod multi_blog; +pub mod sitemap; diff --git a/src/modules/multi_blog.rs b/src/modules/multi_blog.rs index 4831493..3278e13 100644 --- a/src/modules/multi_blog.rs +++ b/src/modules/multi_blog.rs @@ -22,12 +22,10 @@ use std::{ io::Read, }; -use windmark::Response; - -use crate::{success, track_mount, Main}; +use crate::{success, track_mount}; #[allow(clippy::too_many_lines)] -pub fn multi_blog(router: &mut windmark::Router) { +pub fn module(router: &mut windmark::Router) { let paths = read_dir("content/pages/blog").unwrap(); let mut blogs: HashMap<String, HashMap<_, _>> = HashMap::new(); diff --git a/src/modules/sitemap.rs b/src/modules/sitemap.rs new file mode 100644 index 0000000..7e190aa --- /dev/null +++ b/src/modules/sitemap.rs @@ -0,0 +1,38 @@ +// This file is part of Locus <https://github.com/gemrest/locus>. +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// +// 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 <http://www.gnu.org/licenses/>. +// +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// SPDX-License-Identifier: GPL-3.0-only + +pub fn module(router: &mut windmark::Router) { + crate::track_mount( + router, + "/sitemap", + "A map of all publicly available routes on this Gemini capsule", + Box::new(|context| { + crate::success!( + format!( + "# SITEMAP\n\n{}", + (*crate::ROUTES.lock().unwrap()) + .iter() + .map(|(r, d)| format!("=> {} {}", r, d.description)) + .collect::<Vec<_>>() + .join("\n") + ), + context + ) + }), + ); +} |