Skip to content

Commit

Permalink
sort folders by order too
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Oct 1, 2023
1 parent 3aec0dd commit 3d8251c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/builder/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,14 @@ impl TutorialFolder {

pub fn folders_sorted(&self) -> Vec<&TutorialFolder> {
let mut vec = self.folders.iter().collect::<Vec<_>>();
vec.sort_by_key(|t| t.0);
vec.sort_unstable_by(|a, b| {
match (a.1.metadata.clone().and_then(|x| x.order), b.1.metadata.clone().and_then(|x| x.order)) {
(Some(a), Some(b)) => a.cmp(&b),
(Some(_), None) => Ordering::Less,
(None, Some(_)) => Ordering::Greater,
(None, None) => a.0.cmp(&b.0),
}
});
vec.into_iter().map(|(_, v)| v).collect()
}

Expand Down

0 comments on commit 3d8251c

Please sign in to comment.