satelito

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

commit a9646347b041348c328758549aafc3fc93bf807c
parent 86f4e121a89f3eaa19d4207043516dadf191b3cf
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Thu, 29 Sep 2022 22:19:13 -0400

Get a collection even with the pipe command

Diffstat:
Msatelito/file.lua | 6++++++
Msatelito/init.lua | 28++++++++++++++++++++++++----
Msatelito/list.lua | 5-----
Msatelito/site.lua | 7-------
4 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/satelito/file.lua b/satelito/file.lua @@ -104,6 +104,12 @@ function file.is_index(filepath) return (file.get_basename(filepath) == 'index.md') or (file.get_basename(filepath) == 'index.html') end +-- Check if the file is content (markdown or html) +function file.is_content(filepath) + assert(filepath, filepath..' does not exists') + return (mimetypes.guess(filepath) == 'text/x-markdown') or (mimetypes.guess(filepath) == 'text/html') +end + -- Check if the file is lua function file.is_lua(filepath) return (mimetypes.guess(filepath) == 'text/x-lua') diff --git a/satelito/init.lua b/satelito/init.lua @@ -20,7 +20,7 @@ local parser = argparse() :name 'satelito' :description 'Satelito is a static site generator in lua script.' :epilog 'For more info, see https://soucy.cc/git/satelito/file/README.md.html' ---local args +local args -- Set 'init' command init = parser:command('init', 'Init the sample website in your $HOME folder.') @@ -61,7 +61,7 @@ if args['init'] then return end --- Example: '$ find site/content/ -name "*.md" | satelito pipe' +-- Example: '$ find site/content/ | satelito pipe' if args['pipe'] then local configpath = false local config = false @@ -111,6 +111,26 @@ if args['pipe'] then -- Get the meta of the file local meta = model.set(filepath, lume.extend(config, {templates = templates}), contentdir) + -- Collection + -- Get the files of a collection (only for the pipe command) + if meta.collection and type(meta.collection) == 'table' then + for i = 1, #meta.collection do + if lfs.attributes(contentdir..meta.collection[i]).mode == 'directory' then + for collectable in dirtree.get(contentdir..meta.collection[i]) do + if file.is_content(collectable) and file.get_metafile(collectable) then + sitemap[#sitemap+1] = model.set(collectable, lume.extend(config, {templates = templates}), contentdir) + end + end + else + if file.is_content(contentdir..meta.collection[i]) + and file.get_metafile(contentdir..meta.collection[i]) + then + sitemap[#sitemap+1] = model.set(contentdir..meta.collection[i], lume.extend(config, {templates = templates}), contentdir) + end + end + end + end + -- Add the meta of the file into the sitemap table if lume.count(sitemap) == 0 then print('=> Fetching the markdown and HTML content ...') @@ -126,7 +146,7 @@ if args['pipe'] then print('=> Making the web site ...') -- Sorting by alphanum - table.sort(sitemap, function(a, b) return a.idorder > b.idorder end) + table.sort(lume.unique(sitemap), function(a, b) return a.idorder > b.idorder end) return site.make(sitemap, args['export'], timestart) end @@ -169,7 +189,7 @@ if args['make'] then print('=> Making the web site ...') -- Sort before make the website - table.sort(sitemap, function(a, b) return a.idorder > b.idorder end) + table.sort(lume.unique(sitemap), function(a, b) return a.idorder > b.idorder end) site.make(sitemap, args['export'], timestart) diff --git a/satelito/list.lua b/satelito/list.lua @@ -58,7 +58,6 @@ function list.get_collection(collection, sitemap, asc) 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) @@ -73,10 +72,6 @@ function list.get_collection(collection, sitemap, asc) return end -function list.set_collection(collection, sitemap, asc) - print(collection, inspect(sitemap), asc) -end - -- Archives function list.get_archives(contentdir) local archives_table = {} diff --git a/satelito/site.lua b/satelito/site.lua @@ -48,13 +48,6 @@ function site.make(sitemap, export, timestart) sitemap[i].collection = list.get_collection(sitemap[i].collection, sitemap, sitemap[i].asc) end - if sitemap[i].collection and not sitemap[i].list then - --print(inspect(file.get_collection(sitemap[i].path, sitemap[i].contentdir))) - --print(inspect(sitemap[i].collection)) - print(sitemap[i].contentdir, sitemap[i].path) - print(inspect(args)) - end - if i > 1 then sitemap[i].relprev = sitemap[i-1] end