mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Merge pull request #14 from Leeingnyo/change-page-sort
Sort page names alphanumerically
This commit is contained in:
commit
00d2540b95
@ -103,3 +103,7 @@ Reader:
|
|||||||
Mobile UI:
|
Mobile UI:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/0)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/1)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/2)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/3)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/4)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/5)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/6)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/7)
|
||||||
|
@ -2,6 +2,7 @@ require "zip"
|
|||||||
require "mime"
|
require "mime"
|
||||||
require "json"
|
require "json"
|
||||||
require "uri"
|
require "uri"
|
||||||
|
require "./util"
|
||||||
|
|
||||||
struct Image
|
struct Image
|
||||||
property data : Bytes
|
property data : Bytes
|
||||||
@ -44,7 +45,7 @@ class Entry
|
|||||||
["image/jpeg", "image/png"].includes? \
|
["image/jpeg", "image/png"].includes? \
|
||||||
MIME.from_filename? e.filename
|
MIME.from_filename? e.filename
|
||||||
}
|
}
|
||||||
.sort { |a, b| a.filename <=> b.filename }
|
.sort { |a, b| compare_alphanumerically(split_by_alphanumeric(a.filename), split_by_alphanumeric(b.filename)) }
|
||||||
.[page_num - 1]
|
.[page_num - 1]
|
||||||
page.open do |io|
|
page.open do |io|
|
||||||
slice = Bytes.new page.uncompressed_size
|
slice = Bytes.new page.uncompressed_size
|
||||||
|
47
src/util.cr
47
src/util.cr
@ -32,3 +32,50 @@ def request_path_startswith(env, ary)
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_numeric(str)
|
||||||
|
/^\d+/.match(str) != nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def split_by_alphanumeric(str)
|
||||||
|
is_number = false
|
||||||
|
arr = [] of String
|
||||||
|
arr.push(
|
||||||
|
str.split("").reduce("") do |memo, c|
|
||||||
|
if (is_number)
|
||||||
|
if is_numeric(c)
|
||||||
|
memo + c
|
||||||
|
else
|
||||||
|
arr.push(memo) if memo != ""
|
||||||
|
is_number = false
|
||||||
|
c
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if is_numeric(c) # number
|
||||||
|
arr.push(memo) if memo != ""
|
||||||
|
is_number = true
|
||||||
|
c
|
||||||
|
else
|
||||||
|
memo + c
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
arr
|
||||||
|
end
|
||||||
|
|
||||||
|
def compare_alphanumerically(c, d)
|
||||||
|
is_c_bigger = c.size <=> d.size
|
||||||
|
begin
|
||||||
|
c.zip(d) do |a, b|
|
||||||
|
if is_numeric(a) && is_numeric(b)
|
||||||
|
compare = a.to_i <=> b.to_i
|
||||||
|
return compare if compare != 0
|
||||||
|
else
|
||||||
|
compare = a <=> b
|
||||||
|
return compare if compare != 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
is_c_bigger
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user