From 347d7c0da13079fefce6d8741a5604adb89eb97c Mon Sep 17 00:00:00 2001 From: Volpeon Date: Thu, 4 Aug 2022 10:26:57 +0200 Subject: Overhauled metadata handling --- scripts/lib/sort.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 scripts/lib/sort.lua (limited to 'scripts/lib/sort.lua') 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 @@ +local utils = require 'pandoc.utils' + +function page_sort(order, pages) + order = order and utils.stringify(order) + + return function(ref1, ref2) + local p1 = pages and pages[utils.stringify(ref1)] or ref1 + local p2 = pages and pages[utils.stringify(ref2)] or ref2 + + if p1.position then + if p2.position then + return tonumber(utils.stringify(p1.position)) < tonumber(utils.stringify(p2.position)) + else + return true + end + elseif p2.position then + return false + elseif order == "date_desc" then + if p1.last_update then + if p2.last_update then + return utils.stringify(p1.last_update.yyyy_mm_dd) > utils.stringify(p2.last_update.yyyy_mm_dd) + else + return true + end + else + return false + end + else + return utils.stringify(p1.title):upper() < utils.stringify(p2.title):upper() + end + end +end + +return { + page_sort = page_sort +} -- cgit v1.2.3-54-g00ecf