diff options
| author | Fuwn <[email protected]> | 2025-05-27 02:43:36 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-05-27 02:43:36 -0700 |
| commit | b8f61569dbede77a3642bb44f6d213df8f4a9e5e (patch) | |
| tree | 9cc1c1d3f794f99f2fec90c33c67cff1dfa6f43f /src/modules | |
| parent | build(container): Update build steps to remedy over-caching (diff) | |
| download | locus-b8f61569dbede77a3642bb44f6d213df8f4a9e5e.tar.xz locus-b8f61569dbede77a3642bb44f6d213df8f4a9e5e.zip | |
feat(directory): Sort routes by hits
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, ) |