satelito

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

commit 1bd26424c49c1f6d9da400dcc9094b6157540d52
parent eb304309eae1badad09a770e195d76862f619981
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Thu, 24 Nov 2022 23:37:33 -0500

Refactor init to gain clarity and maybe speed (who knows)

Diffstat:
Msatelito/init.lua | 150+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 85 insertions(+), 65 deletions(-)

diff --git a/satelito/init.lua b/satelito/init.lua @@ -15,6 +15,7 @@ local init local pipe local make local exec +local test local parser = argparse() :name 'satelito' @@ -34,8 +35,47 @@ make:flag('-e --export', 'Export the outputed HTML in the *config.paths.public_h exec = parser:command('exec', 'Execute a script frome the bin directory') exec:argument 'bin name' +test = parser:command('test', '') + args = parser:parse() +-- Started +print('=> Satelito is on ...') + +------------- +-- GLOBALS -- +------------- + +-- Set the Satelito global table +_G.Satelito = {} +_G.Satelito.timestart = os.time() + +-- Put config.lua in a table +print('=> Fetching the configuration file content ...') +_G.Satelito.config = dofile(site.get_config(lfs.currentdir()..'/')) + +-- Change current directory for the config.lua's directory +print('=> Moving where the site configuration file is located ...') +lfs.chdir(file.get_dirname(site.get_config(lfs.currentdir()..'/'))) + +-- Then add the current directory to the package.path +package.path = package.path .. ';'.. lfs.currentdir() ..'/?.lua' + +-- Get the absolute path for the 'content' directory +_G.Satelito.contentdir = lfs.currentdir()..'/'.._G.Satelito.config.paths.content + +-- Get the absolute path for the 'public_html' directory +_G.Satelito.publicdir = lfs.currentdir()..'/'.._G.Satelito.config.paths.public_html + +-- Get the list of templates +print('=> Fetching the templates ...') +_G.Satelito.templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. _G.Satelito.config.paths.templates)) + + +---------- +-- EXEC -- +---------- + if args['exec'] then package.path = package.path .. ';'.. lfs.currentdir() ..'/?.lua' @@ -47,6 +87,11 @@ if args['exec'] then end +---------- +-- INIT -- +---------- + +-- Initialize the satelito sample site in $HOME -- Example '$ satelito init' if args['init'] then os.execute('mkdir ~/satelito-sample') @@ -61,83 +106,54 @@ if args['init'] then return end +print(inspect(Satelito)) +print(lfs.currentdir()) + +---------- +-- PIPE -- +---------- + +-- Pipe stdout into satelito -- Example: '$ find site/content/ | satelito pipe' if args['pipe'] then - local configpath = false - local config = false - local contentdir = false + local config = _G.Satelito.config; + local contentdir = _G.Satelito.contentdir local sitemap = {} - local templates + local templates = _G.Satelito.templates local timestart = os.time() - print('=> Satelito is on ...') - for filepath in (io.lines()) do - if file.is_markdown(filepath) or file.is_html(filepath) then - -- Get the site configuration's path - if not configpath then - print('=> Searching for the nearest config.lua ...') - configpath = site.get_config(filepath) - end - - -- Change the current directory to the config's directory - if lfs.currentdir()..'/' ~= file.get_dirname(configpath) then - print('=> Moving where the configuration file is located ...') - lfs.chdir(file.get_dirname(configpath)) - end - - -- If the site configuration file exists - if file.exists(configpath) then - -- Add the currentdir to the package.path - package.path = package.path .. ';'.. lfs.currentdir() ..'/?.lua' - - -- Set config.lua in a table - if not config then - print('=> Fetching the configuration file content ...') - config = require 'config' - end - - -- Absolute path to the 'content/' directory - if not contentdir then - contentdir = lfs.currentdir() .. '/' .. config.paths.content - end - - -- Get the list of templates - if not templates then - print('=> Fetching the templates ...') - templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates)) - end - - -- 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) + if file.is_content(filepath) 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 ...') - end - - sitemap[#sitemap+1] = meta + -- Add the meta of the file into the sitemap table + if lume.count(sitemap) == 0 then + print('=> Fetching the markdown and HTML content ...') end + + sitemap[#sitemap+1] = meta + end end @@ -151,6 +167,10 @@ if args['pipe'] then return site.make(sitemap, args['export'], timestart) end +---------- +-- MAKE -- +---------- + -- Make command -- Example: '$ satelito make --export' if args['make'] then