satelito

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

commit a607ebeeb9829e4fcedab3402d154ab1b36772df
parent 02529ec0871ce3a902ca320ea00f1a2c02b1e9ec
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Mon, 28 Nov 2022 08:06:22 -0500

Try to simplify the collection feature

Diffstat:
Msatelito/file.lua | 26+++++++++++++++++++++++---
Msatelito/init.lua | 27++++++++++++---------------
Msatelito/list.lua | 21+--------------------
Msatelito/model.lua | 8+++++++-
Msatelito/site.lua | 6+++---
5 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/satelito/file.lua b/satelito/file.lua @@ -123,13 +123,13 @@ function file.get_rellink(filepath, dirname) end end --- -function file.get_collection(filepath, dirname) +-- Get a list of relative children paths from a filepath +function file.get_list(filepath, dirname) local collection = {} for subfilepath in dirtree.get(file.get_dirname(filepath)) do if subfilepath - and (file.is_markdown(subfilepath) or file.is_html(subfilepath)) + and file.is_content(subfilepath) and not file.is_index(subfilepath) then collection[#collection+1] = file.get_relpath(subfilepath, dirname) @@ -139,6 +139,26 @@ function file.get_collection(filepath, dirname) return collection end +-- Get a table collection of contents +function file.get_collection(collection) + if collection and type(collection) == 'table' then + local collection_list = {} + local contentdir = _G.Satelito.contentdir + + for i = 1, #collection do + if lfs.attributes(contentdir..collection[i]).mode == 'directory' then + collection_list[#collection_list+1] = file.get_list(contentdir..collection[i], contentdir) + else + collection_list[#collection_list+1] = { collection[i] } + end + end + + return lume.concat(table.unpack(collection_list)) + end + + return +end + -- Create a dirtree function file.mkdir(filepath) local sep, pStr = package.config:sub(1, 1), '' diff --git a/satelito/init.lua b/satelito/init.lua @@ -124,24 +124,17 @@ if args['pipe'] then if file.is_content(filepath) then -- Get the pagedata of the file local pagedata = model.set(filepath) + local collection_data = {} + + -- + -- List + -- -- Collection -- Get the files of a collection (only for the pipe command) - if pagedata.collection and type(pagedata.collection) == 'table' then - for i = 1, #pagedata.collection do - if lfs.attributes(contentdir..pagedata.collection[i]).mode == 'directory' then - for collectable in dirtree.get(contentdir..pagedata.collection[i]) do - if file.is_content(collectable) and file.get_metafile(collectable) then - sitedata[#sitedata+1] = model.set(collectable) - end - end - else - if file.is_content(contentdir..pagedata.collection[i]) - and file.get_metafile(contentdir..pagedata.collection[i]) - then - sitedata[#sitedata+1] = model.set(contentdir..pagedata.collection[i]) - end - end + if pagedata.collection and pagedata.collection_list then + for i = 1, #pagedata.collection_list do + collection_data[#collection_data+1] = model.set(contentdir..pagedata.collection_list[i]) end end @@ -151,6 +144,7 @@ if args['pipe'] then end sitedata[#sitedata+1] = pagedata + lume.extend(sitedata, collection_data) end end @@ -169,6 +163,9 @@ if args['pipe'] then print('=> '..lume.count(sitedata)..' content found') print('=> Making the web site ...') + local count_test = lume.count(lume.unique(sitedata)) + print(count_test) + -- Sorting by alphanum table.sort(lume.unique(sitedata), function(a, b) return a.idorder > b.idorder end) diff --git a/satelito/list.lua b/satelito/list.lua @@ -29,7 +29,7 @@ function list.set_pagination(pagelist, len) return slicedlist end --- Children +-- Get children contents function list.get_children(children_list, sitemap, asc) local children = {} @@ -53,25 +53,6 @@ function list.get_children(children_list, sitemap, asc) return children end -function list.get_collection(collection, sitemap, asc) - if collection and type(collection) == 'table' then - local collection_list = {} - local contentdir = lfs.currentdir()..'/'..sitemap[1].paths.content - - for i = 1, #collection do - if lfs.attributes(contentdir..collection[i]).mode == 'directory' then - collection_list[#collection_list+1] = file.get_collection(contentdir..collection[i], contentdir) - else - collection_list[#collection_list+1] = { collection[i] } - end - end - - return list.get_children(lume.concat(table.unpack(collection_list)), sitemap, asc) - end - - return -end - -- Archives function list.get_archives(contentdir) local archives_table = {} diff --git a/satelito/model.lua b/satelito/model.lua @@ -62,7 +62,13 @@ function model.set(filepath) -- List (and Feed) if file.is_index(filepath) and pagedata.list ~= false then - pagedata.list = file.get_collection(filepath, contentdir) + pagedata.list = file.get_list(filepath, contentdir) + end + + -- Collection + -- File list + if pagedata.collection then + pagedata.collection_list = file.get_collection(pagedata.collection) end -- Archives diff --git a/satelito/site.lua b/satelito/site.lua @@ -46,9 +46,9 @@ function site.make(sitedata) sitedata[i].children = list.get_children(sitedata[i].list, sitedata, sitedata[i].asc) end - if sitedata[i].collection then - sitedata[i].collection = list.get_collection(sitedata[i].collection, sitedata, sitedata[i].asc) - end + -- if sitedata[i].collection and sitedata[i].collection_list then + -- sitedata[i].collection = list.get_children(sitedata[i].collection_list, sitedata, sitedata[i].asc) + -- end if i > 1 then sitedata[i].relprev = sitedata[i-1]