From f60823c3f593bfbf4a00d16e794d4e47d82da9c2 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 14 Apr 2022 18:48:19 -0700 Subject: feat: descriptions for sitemap --- src/macros.rs | 10 ++++++---- src/main.rs | 51 +++++++++++++++++++++++++++++++++++++-------------- src/modules.rs | 7 +++++++ 3 files changed, 50 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/macros.rs b/src/macros.rs index 997f7d5..fe1f20b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -18,8 +18,9 @@ #[macro_export] macro_rules! mount_page { - ($router:ident, $at:literal, $file:literal) => { - (*crate::ROUTES.lock().unwrap()).push($at.to_string()); + ($router:ident, $at:literal, $description:literal, $file:literal) => { + (*crate::ROUTES.lock().unwrap()) + .insert($at.to_string(), $description.to_string()); ($router).mount( $at, @@ -46,8 +47,9 @@ macro_rules! mount_page { #[macro_export] macro_rules! mount_file { - ($router:ident, $at:literal, $file:literal) => { - (*crate::ROUTES.lock().unwrap()).push($at.to_string()); + ($router:ident, $at:literal, $description:literal, $file:literal) => { + (*crate::ROUTES.lock().unwrap()) + .insert($at.to_string(), $description.to_string()); ($router).mount( $at, diff --git a/src/main.rs b/src/main.rs index 5404af9..2c5c7f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ mod modules; #[macro_use] extern crate log; -use std::{lazy::SyncLazy, sync::Mutex}; +use std::{collections::HashMap, lazy::SyncLazy, sync::Mutex}; use constants::QUOTES; use pickledb::PickleDb; @@ -61,8 +61,8 @@ static DATABASE: SyncLazy> = SyncLazy::new(|| { } }) }); -static ROUTES: SyncLazy>> = - SyncLazy::new(|| Mutex::new(vec![])); +static ROUTES: SyncLazy>> = + SyncLazy::new(|| Mutex::new(HashMap::new())); #[derive(Template)] #[template(path = "main")] @@ -87,9 +87,10 @@ fn hits_from_route(route: &str) -> i32 { fn track_mount( router: &mut Router, route: &str, + description: &str, handler: windmark::handler::RouteResponse, ) { - (*ROUTES.lock().unwrap()).push(route.to_string()); + (*ROUTES.lock().unwrap()).insert(route.to_string(), description.to_string()); router.mount(route, handler); } @@ -146,6 +147,7 @@ async fn main() -> Result<(), Box> { track_mount( &mut router, "/uptime", + "The uptime of Locus, in seconds (A.K.A., The Locus Epoch)", Box::new(move |context| { success!( &format!("# UPTIME\n\n{} seconds", uptime.elapsed().as_secs()), @@ -168,15 +170,35 @@ async fn main() -> Result<(), Box> { ); time_mount = Instant::now(); - mount_file!(router, "/robots.txt", "robots.txt"); - mount_file!(router, "/favicon.txt", "favicon.txt"); - mount_page!(router, "/", "index"); - mount_page!(router, "/contact", "contact"); - mount_page!(router, "/donate", "donate"); - mount_page!(router, "/gemini", "gemini"); - mount_page!(router, "/gopher", "gopher"); - mount_page!(router, "/interests", "interests"); - mount_page!(router, "/skills", "skills"); + mount_file!( + router, + "/robots.txt", + "Crawler traffic manager, for robots, not humans", + "robots.txt" + ); + mount_file!( + router, + "/favicon.txt", + "This Gemini capsule's icon", + "favicon.txt" + ); + mount_page!(router, "/", "This Gemini capsule's homepage", "index"); + mount_page!(router, "/contact", "Many ways to contact Fuwn", "contact"); + mount_page!(router, "/donate", "Many ways to donate to Fuwn", "donate"); + mount_page!( + router, + "/gemini", + "Information and resources for the Gemini protocol", + "gemini" + ); + mount_page!( + router, + "/gopher", + "Information and resources for the Gopher protocol", + "gopher" + ); + mount_page!(router, "/interests", "A few interests of Fuwn", "interests"); + mount_page!(router, "/skills", "A few skills of Fuwn", "skills"); info!( "static mounts took {}ms", @@ -186,13 +208,14 @@ async fn main() -> Result<(), Box> { 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| format!("=> {}", r)) + .map(|(r, d)| format!("=> {} {}", r, d)) .collect::>() .join("\n") ), diff --git a/src/modules.rs b/src/modules.rs index 8189fb3..7e8a5bb 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -106,6 +106,7 @@ pub fn multi_blog(router: &mut windmark::Router) { track_mount( router, "/blog", + "Fuwn's blogs", Box::new(move |context| { success!( &format!( @@ -135,10 +136,12 @@ pub fn multi_blog(router: &mut windmark::Router) { let fixed_blog_name = blog.replace(' ', "_").to_lowercase(); let entries_clone = entries.clone(); let fixed_blog_name_clone = fixed_blog_name.clone(); + let blog_clone = blog.clone(); track_mount( router, &format!("/blog/{}", fixed_blog_name), + &format!("{} ― One of Fuwn's blogs", &blog), Box::new(move |context| { success!( &format!( @@ -173,6 +176,10 @@ pub fn multi_blog(router: &mut windmark::Router) { track_mount( router, &format!("/blog/{}/{}", fixed_blog_name, title.to_lowercase()), + &format!( + "{}, {} ― An entry to one of Fuwn's blogs", + title, blog_clone + ), Box::new(move |context| success!(contents, context)), ); } -- cgit v1.2.3