satelito

Static [web] site (or page) generator (ssg) made with Lua script.
git clone git://soucy.cc/satelito.git
Log | Files | Refs | README

commit 58ec93a162331635271206247bd3130207b55f1b
parent f1f79b3886ef345cb6b429470e4d74797f2d2c18
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Thu, 10 Mar 2022 06:33:08 -0500

Set the sequence function

Diffstat:
Msatelito/site.lua | 53++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/satelito/site.lua b/satelito/site.lua @@ -30,7 +30,7 @@ function site.get_config(filepath) end -- Make the site -function site.make(sitemap, templates, export, timestart) +function site.make(sitemap, templates, export, timestart, config) for i = 1, #sitemap do local html, html_path local feed_xml, feed_xml_path @@ -39,16 +39,50 @@ function site.make(sitemap, templates, export, timestart) sitemap[i].children = list.get_children(sitemap[i].list, sitemap, sitemap[i].asc) sitemap[i].collection = list.get_collection(sitemap[i].collection, sitemap, sitemap[i].asc) + -- Get a sequence of pages for sequential navigation + sitemap[i].sequence = function(seqname) + if config.sequence[seqname] then + local _sequence = {} + local seq = list.get_collection(config.sequence[seqname].scope, sitemap, config.sequence[seqname].asc or false) + + if seq then + _sequence.length = #seq + _sequence.current = lume.find(seq, sitemap[i]) + + if _sequence.current > 1 then + _sequence.relprev = seq[(_sequence.current - 1)] + end + + if _sequence.current < _sequence.length then + _sequence.relnext = seq[(_sequence.current + 1)] + end + + if config.sequence[seqname].divider then + _sequence.relup = math.ceil(_sequence.current / config.sequence[seqname].divider) + end + + return _sequence + end + end + + return + end + -- If a pagination is requested if sitemap[i].pagination and file.is_index(sitemap[i].relpath) then + print('=> A pagination is requested ...') + sitemap[i].pagination.limit = sitemap[i].pagination.limit or 6 sitemap[i].pagination.prefix = sitemap[i].pagination.prefix or 'pg-' -- Split page children by pagination limit paginated = list.set_pagination(sitemap[i].collection or sitemap[i].children, sitemap[i].pagination.limit) + -- Set the pagination length sitemap[i].pagination.length = #paginated + print('=> Making the pagination pages ...') + for p = 1, #paginated do sitemap[i].children = paginated[p] sitemap[i].pagination.current = p @@ -69,16 +103,17 @@ function site.make(sitemap, templates, export, timestart) print(html) end end - else - -- Make the page - html, html_path = page.make(sitemap[i], templates) - -- Export the page - if export then - file.export(html_path, html) else - print(html) - end + -- Make the page + html, html_path = page.make(sitemap[i], templates) + + -- Export the page + if export then + file.export(html_path, html) + else + print(html) + end end -- Feed