aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-05-27 02:43:36 -0700
committerFuwn <[email protected]>2025-05-27 02:43:36 -0700
commitb8f61569dbede77a3642bb44f6d213df8f4a9e5e (patch)
tree9cc1c1d3f794f99f2fec90c33c67cff1dfa6f43f /src/modules
parentbuild(container): Update build steps to remedy over-caching (diff)
downloadlocus-b8f61569dbede77a3642bb44f6d213df8f4a9e5e.tar.xz
locus-b8f61569dbede77a3642bb44f6d213df8f4a9e5e.zip
feat(directory): Sort routes by hits
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/directory.rs25
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,
)