Skip to content

Commit

Permalink
fix(api_ref): stabilize sort
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Oct 15, 2024
1 parent df26184 commit 0a41adc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions crates/rari-doc/src/templ/templs/css_ref.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap};
use std::sync::LazyLock;

Expand Down Expand Up @@ -221,12 +222,10 @@ pub fn css_ref() -> Result<String, DocError> {
out.push_str("<h3>");
out.push(letter);
out.push_str("</h3><ul>");
for (url, label) in items.into_iter().sorted_by(|(_, a), (_, b)| {
a.trim_matches(|c: char| !c.is_ascii_alphabetic() && c != '(' && c != ')' && c != '-')
.cmp(b.trim_matches(|c: char| {
!c.is_ascii_alphabetic() && c != '(' && c != ')' && c != '-'
}))
}) {
for (url, label) in items
.into_iter()
.sorted_by(|(_, a), (_, b)| compare_items(a, b))
{
out.extend([
"<li>",
&RariApi::link(
Expand All @@ -247,6 +246,19 @@ pub fn css_ref() -> Result<String, DocError> {
Ok(out)
}

fn compare_items(a: &str, b: &str) -> Ordering {
let ord = a
.trim_matches(|c: char| !c.is_ascii_alphabetic() && c != '(' && c != ')' && c != '-')
.cmp(
b.trim_matches(|c: char| !c.is_ascii_alphabetic() && c != '(' && c != ')' && c != '-'),
);
if ord == Ordering::Equal {
a.cmp(b)
} else {
ord
}
}

fn initial_letter(s: &str) -> char {
s.chars()
.find(|&c| c.is_ascii_alphabetic() || c == '-')
Expand Down

0 comments on commit 0a41adc

Please sign in to comment.