diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/directory.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/modules/directory.rs b/src/modules/directory.rs index 9eddc31..4179175 100644 --- a/src/modules/directory.rs +++ b/src/modules/directory.rs @@ -1,3 +1,5 @@ +use crate::route::hits_from; + pub fn module(router: &mut windmark::router::Router) { crate::route::track_mount( router, @@ -8,11 +10,24 @@ pub fn module(router: &mut windmark::router::Router) { &format!( "# Directory\n\nA map of all publicly available routes on this \ Gemini capsule\n\n{}", - (*crate::route::ROUTES.lock().unwrap()) - .iter() - .map(|(r, d)| format!("=> {} {}", r, d.description)) - .collect::<Vec<_>>() - .join("\n") + { + let mut lines = (*crate::route::ROUTES.lock().unwrap()) + .iter() + .map(|(r, d)| format!("=> {} {}", r, d.description)) + .collect::<Vec<_>>(); + let standard_transform = |route: &str| { + route.replace("=> ", "").split(' ').collect::<Vec<_>>()[0] + .to_string() + }; + + lines.sort_by(|a, b| { + hits_from(&standard_transform(a)) + .cmp(&hits_from(&standard_transform(b))) + }); + lines.reverse(); + + lines.join("\n") + } ), &context, ) |