diff options
Diffstat (limited to 'scripts/lib/sort.lua')
| -rw-r--r-- | scripts/lib/sort.lua | 36 |
1 files changed, 36 insertions, 0 deletions
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 | } | ||
