From 6c81b7e3e6119e91160581a2e8f393df8424abe6 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 11 Jun 2022 18:44:07 +0200 Subject: Fixed page ordering in level 3 lists --- assets/css/components/_hnav.scss | 2 +- content/art/index.md | 1 + scripts/metadata_filter.lua | 229 +++++++++++++++++++++------------------ yarn.lock | 2 +- 4 files changed, 124 insertions(+), 110 deletions(-) diff --git a/assets/css/components/_hnav.scss b/assets/css/components/_hnav.scss index 5f34e8c..74dba9f 100644 --- a/assets/css/components/_hnav.scss +++ b/assets/css/components/_hnav.scss @@ -4,7 +4,7 @@ @include iro.props-namespace('hnav') { @include iro.props-store(( --colors: ( - --border: fn.global-color(--obj-hi) + --border: fn.global-color(--obj) ) ), 'colors'); diff --git a/content/art/index.md b/content/art/index.md index eadac7a..0b5072b 100644 --- a/content/art/index.md +++ b/content/art/index.md @@ -2,6 +2,7 @@ title: Art position: 2 list_layout: small-gallery +list_order: date_desc list_limit: 6 feed: true --- diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 4ac4a4d..fcceffa 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -1,5 +1,13 @@ local path = require 'pandoc.path' +function pandoc.List:flatten() + local result = pandoc.List() + + for i = 1, #self do result:extend(self[i]) end + + return result +end + function pandoc.List:flatMap(fn) local mapped = self:map(fn) local result = pandoc.List() @@ -19,6 +27,32 @@ function pandoc.List:take(n) return result end +function page_sort(order) + return function(p1, p2) + if p1.position then + if p2.position then + return tonumber(p1.position) < tonumber(p2.position) + else + return true + end + elseif p2.position then + return false + elseif order == "date_desc" then + if p1.date then + if p2.date then + return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd + else + return true + end + else + return false + end + else + return p1.title:upper() < p2.title:upper() + end + end +end + function slug(str) return str:lower():gsub("[^ a-z]", ""):gsub("[ ]+", "-") end @@ -135,41 +169,8 @@ function process_pages(global, order, pages_by_id) end end - pages_all:sort(function(p1, p2) - if p1.position then - if p2.position then - return tonumber(p1.position) < tonumber(p2.position) - else - return true - end - elseif p2.position then - return false - elseif order == "date_desc" then - if p1.date then - if p2.date then - return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd - else - return true - end - else - return false - end - else - return p1.title:upper() < p2.title:upper() - end - end) - - pages_date_desc:sort(function(p1, p2) - if p1.position then - if p2.position then - return tonumber(p1.position) < tonumber(p2.position) - else - return true - end - else - return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd - end - end) + pages_all:sort(page_sort(order)) + pages_date_desc:sort(page_sort("date_desc")) local pages_data = { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } @@ -199,6 +200,7 @@ function generate_list(meta) title = p.title, subtitle = p.subtitle, date = p.date, + position = p.position, url = p.url, slug = p.slug, thumbnail = p.thumbnail, @@ -208,85 +210,96 @@ function generate_list(meta) } end) elseif meta.depth == "2" then - return meta.pages.all:map(function(cat) - local limit = (cat.list_limit and tonumber(pandoc.utils.stringify(cat.list_limit))) or - 9999 - local allItems = ((cat.pages and cat.pages.all) or pandoc.List()):map(function(p) + return meta.pages.all + :map(function(cat) + local limit = (cat.list_limit and tonumber(pandoc.utils.stringify(cat.list_limit))) or + 9999 + local allItems = ((cat.pages and cat.pages.all) or pandoc.List()):map(function(p) + return { + title = p.title, + subtitle = p.subtitle, + date = p.date, + position = p.position, + url = p.url, + slug = p.slug, + thumbnail = p.thumbnail, + icon = p.icon or cat.icon, + post_icon = p.post_icon or cat.list_post_icon or meta.list_post_icon, + indicator = cat.list_read_indicators, + } + end) + local items = allItems:take(limit) + local omitted = #allItems - #items + return { - title = p.title, - subtitle = p.subtitle, - date = p.date, - url = p.url, - slug = p.slug, - thumbnail = p.thumbnail, - icon = p.icon or cat.icon, - post_icon = p.post_icon or cat.list_post_icon or meta.list_post_icon, - indicator = cat.list_read_indicators, + title = cat.title, + description = (cat.description and pandoc.MetaBlocks(pandoc.Para(cat.description))) or + (not cat.no_description and cat.content), + url = cat.url, + slug = cat.slug, + layout = cat.list_layout, + items = items, + total = tostring(#allItems), + omitted = omitted ~= 0 and tostring(omitted), } end) - local items = allItems:take(limit) - local omitted = #allItems - #items - - return { - title = cat.title, - description = (cat.description and pandoc.MetaBlocks(pandoc.Para(cat.description))) or - (not cat.no_description and cat.content), - url = cat.url, - slug = cat.slug, - layout = cat.list_layout, - items = items, - total = tostring(#allItems), - omitted = omitted ~= 0 and tostring(omitted), - } - end):filter(function(cat) return #cat.items ~= 0 end) + :filter(function(cat) return #cat.items ~= 0 end) elseif meta.depth == "3" then - return meta.pages.all:map(function(cat) - local limit = (cat.list_limit and tonumber(pandoc.utils.stringify(cat.list_limit))) or - 9999 - local allItems = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c) - if c.pages then - return c.pages.all:map(function(p) - return { - title = p.title, - subtitle = p.subtitle, - category = c.title, - url = p.url, - slug = p.slug, - thumbnail = p.thumbnail, - icon = p.icon or c.icon, - post_icon = p.post_icon or c.list_post_icon or cat.list_post_icon, - indicator = c.list_read_indicators, - } + return meta.pages.all + :map(function(cat) + local limit = (cat.list_limit and tonumber(pandoc.utils.stringify(cat.list_limit))) or + 9999 + local allItems = (cat.pages and cat.pages.all or pandoc.List()) + :flatMap(function(c) + if c.pages then + return c.pages.all:map(function(p) + return { + title = p.title, + subtitle = p.subtitle, + date = p.date, + position = p.position, + category = c.title, + url = p.url, + slug = p.slug, + thumbnail = p.thumbnail, + icon = p.icon or c.icon, + post_icon = p.post_icon or c.list_post_icon or cat.list_post_icon, + indicator = c.list_read_indicators, + } + end) + else + local l = pandoc.List() + l:insert({ + title = c.title, + subtitle = c.subtitle, + date = c.date, + position = c.position, + url = c.url, + slug = c.slug, + icon = c.icon or cat.icon, + post_icon = c.post_icon or cat.list_post_icon, + indicator = cat.list_read_indicators, + }) + return l + end end) - else - local l = pandoc.List() - l:insert({ - title = c.title, - subtitle = c.subtitle, - url = c.url, - slug = c.slug, - icon = c.icon or cat.icon, - post_icon = c.post_icon or cat.list_post_icon, - indicator = cat.list_read_indicators, - }) - return l - end - end) - local items = allItems:take(limit) - local omitted = #allItems - #items + allItems:sort(page_sort(cat.list_order)) + local items = allItems:take(limit) + local omitted = #allItems - #items - return { - title = cat.title, - description = (cat.description and pandoc.MetaBlocks(pandoc.Para(cat.description))) or - (not cat.no_description and cat.content), - url = cat.url, - slug = cat.slug, - layout = cat.list_layout, - items = items, - total = tostring(#allItems), - omitted = omitted ~= 0 and tostring(omitted), - } - end):filter(function(cat) return #cat.items ~= 0 end) + return { + title = cat.title, + description = (cat.description and pandoc.MetaBlocks(pandoc.Para(cat.description))) or + (not cat.no_description and cat.content), + url = cat.url, + slug = cat.slug, + layout = cat.list_layout, + items = items, + total = tostring(#allItems), + omitted = omitted ~= 0 and tostring(omitted), + } + end) + :filter(function(cat) return #cat.items ~= 0 end) end end diff --git a/yarn.lock b/yarn.lock index 457fe0c..715491b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1280,7 +1280,7 @@ internal-slot@^1.0.3: "iro-design@git+https://git.vulpes.one/git/iro-design.git": version "1.0.0" - resolved "git+https://git.vulpes.one/git/iro-design.git#e1b8b497f6935934be25c4c417bbe868594fa7a5" + resolved "git+https://git.vulpes.one/git/iro-design.git#2e5311284e338baeb6bb3dfedb7b3d77a36df682" dependencies: "@oddbird/blend" "^0.2.3" include-media "^1.4.9" -- cgit v1.2.3-54-g00ecf