Add smart sort to index building
This commit is contained in:
parent
ebefccec74
commit
32129d1794
|
@ -76,7 +76,22 @@ my method add-path(%index: $path, $value) {
|
|||
my method render-index(%index:) {
|
||||
# TODO sort these properly
|
||||
my @elements = [];
|
||||
for %index.keys -> $key {
|
||||
my sub compare-with-numbers($a, $b) {
|
||||
my $a-match = $a ~~ /^(.+?)(\d*)(\.\w+)$/;
|
||||
my $b-match = $b ~~ /^(.+?)(\d*)(\.\w+)$/;
|
||||
($a-match[0] cmp $b-match[0]) || ($a-match[1].Int <=> $b-match[1].Int)
|
||||
}
|
||||
my sub compare-keys($key1, $key2) {
|
||||
if $key1 ~~ Str && $key2 ~~ Str {
|
||||
compare-with-numbers($key1, $key2)
|
||||
} elsif $key1 ~~ Str {
|
||||
Order::Less
|
||||
} else {
|
||||
Order::More
|
||||
}
|
||||
}
|
||||
my @keys = %index.keys.sort(&compare-keys);
|
||||
for @keys -> $key {
|
||||
given %index{$key} {
|
||||
when Str {
|
||||
my $x = $_;
|
||||
|
|
Loading…
Reference in a new issue