diff options
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/common.lua | 10 | ||||
-rw-r--r-- | scripts/lib/sort.lua | 36 |
2 files changed, 46 insertions, 0 deletions
diff --git a/scripts/lib/common.lua b/scripts/lib/common.lua index 80b81ba..5ed3e31 100644 --- a/scripts/lib/common.lua +++ b/scripts/lib/common.lua | |||
@@ -49,6 +49,16 @@ function pandoc.List:take(n) | |||
49 | return result | 49 | return result |
50 | end | 50 | end |
51 | 51 | ||
52 | function pandoc.List:skip(n) | ||
53 | local result = pandoc.List() | ||
54 | |||
55 | if n >= #self then return result end | ||
56 | |||
57 | for i = n + 1, #self do result:insert(self[i]) end | ||
58 | |||
59 | return result | ||
60 | end | ||
61 | |||
52 | return { | 62 | return { |
53 | dump = dump | 63 | dump = dump |
54 | } | 64 | } |
diff --git a/scripts/lib/sort.lua b/scripts/lib/sort.lua new file mode 100644 index 0000000..393e5d5 --- /dev/null +++ b/scripts/lib/sort.lua | |||
@@ -0,0 +1,36 @@ | |||
1 | local utils = require 'pandoc.utils' | ||
2 | |||
3 | function page_sort(order, pages) | ||
4 | order = order and utils.stringify(order) | ||
5 | |||
6 | return function(ref1, ref2) | ||
7 | local p1 = pages and pages[utils.stringify(ref1)] or ref1 | ||
8 | local p2 = pages and pages[utils.stringify(ref2)] or ref2 | ||
9 | |||
10 | if p1.position then | ||
11 | if p2.position then | ||
12 | return tonumber(utils.stringify(p1.position)) < tonumber(utils.stringify(p2.position)) | ||
13 | else | ||
14 | return true | ||
15 | end | ||
16 | elseif p2.position then | ||
17 | return false | ||
18 | elseif order == "date_desc" then | ||
19 | if p1.last_update then | ||
20 | if p2.last_update then | ||
21 | return utils.stringify(p1.last_update.yyyy_mm_dd) > utils.stringify(p2.last_update.yyyy_mm_dd) | ||
22 | else | ||
23 | return true | ||
24 | end | ||
25 | else | ||
26 | return false | ||
27 | end | ||
28 | else | ||
29 | return utils.stringify(p1.title):upper() < utils.stringify(p2.title):upper() | ||
30 | end | ||
31 | end | ||
32 | end | ||
33 | |||
34 | return { | ||
35 | page_sort = page_sort | ||
36 | } | ||