diff options
| -rw-r--r-- | src/main.rs | 1 | ||||
| -rw-r--r-- | src/modules/mod.rs | 1 | ||||
| -rw-r--r-- | src/modules/random.rs | 38 | ||||
| -rw-r--r-- | src/modules/search.rs | 6 |
4 files changed, 44 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 8be963f..6ab7086 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,6 +151,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { router.attach_stateless(modules::search::module); router.attach_stateless(modules::remarks::module); router.attach_stateless(modules::multi_blog::module); + router.attach_stateless(modules::random::module); }); time_mounts("static", &mut time_mount, || { diff --git a/src/modules/mod.rs b/src/modules/mod.rs index c5d4aaa..bb822b3 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -17,6 +17,7 @@ // SPDX-License-Identifier: GPL-3.0-only pub mod multi_blog; +pub mod random; pub mod remarks; pub mod search; pub mod sitemap; diff --git a/src/modules/random.rs b/src/modules/random.rs new file mode 100644 index 0000000..8604d64 --- /dev/null +++ b/src/modules/random.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 + +use rand::seq::SliceRandom; + +pub fn module(router: &mut windmark::Router) { + crate::route::track_mount( + router, + "/random", + "Get redirected to a random route", + Box::new(|_| { + windmark::Response::TemporaryRedirect( + (*crate::ROUTES.lock().unwrap()) + .iter() + .collect::<Vec<_>>() + .choose(&mut rand::thread_rng()) + .unwrap() + .0 + .to_string(), + ) + }), + ); +} diff --git a/src/modules/search.rs b/src/modules/search.rs index 9ea235f..06f6152 100644 --- a/src/modules/search.rs +++ b/src/modules/search.rs @@ -24,8 +24,10 @@ pub fn module(router: &mut windmark::Router) { "/search", "A search engine for this Gemini capsule", Box::new(|context| { - let mut response = - String::from("# SEARCH\n\n=> /search?action=go Search!"); + let mut response = String::from( + "# SEARCH\n\n=> /search?action=go Search!\n=> /random I'm Feeling \ + Lucky", + ); if let Some(query) = context.url.query_pairs().next() { if query.0 == "action" && query.1 == "go" { |