satelito

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

commit 9e5a9e37c1e606b3567145577c810133fe008862
parent 37d2ed7efe54fd52c34cba91ca4f05aef81c67ea
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Tue, 30 Mar 2021 08:49:08 -0400

Add the make command

Diffstat:
Msatelito/init.lua | 58++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 52 insertions(+), 6 deletions(-)

diff --git a/satelito/init.lua b/satelito/init.lua @@ -1,7 +1,12 @@ #!/usr/bin/env lua -- +local model = require 'satelito.model' local argparse = require 'argparse' +local inspect = require 'inspect' +local lfs = require 'lfs' +local lume = require 'satelito.lib.lume.lume' local assets = require 'satelito.assets' +local dirtree = require 'satelito.dirtree' local feed = require 'satelito.feed' local file = require 'satelito.file' local page = require 'satelito.page' @@ -11,16 +16,17 @@ local parser = argparse() :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 init +local make local args parser:mutex( - parser:option('-f --file', 'Input a markdown filepath.'), - parser:flag('-p --pipeline', 'Input one or more markdown files through the pipeline.') - --parser:flag('-s --site', 'Explicitly process the content in site mode instead of the default page mode.') + parser:option('-f --file', 'Input a markdown filepath.'), + parser:flag('-p --pipeline', 'Input one or more markdown files through the pipeline.') ) parser:flag('-e --export', 'Export the outputed HTML in the *paths.public_html* folder.') init = parser:command('init', 'Init the sample website in your $HOME folder.') +make = parser:command('make', 'Explicitly process the content in site mode instead of the default page mode.') args = parser:parse() @@ -38,7 +44,7 @@ if args['init'] then end if args['file'] and file.is_markdown(args['file']) then - local html, html_path = page.build(args['file']) + local html, html_path = page.build(args['file'], model.get(args['file'])) if args['export'] then page.export(html_path, html) @@ -54,7 +60,8 @@ if args['pipeline'] then -- for filepath in (io.lines()) do if file.is_markdown(filepath) then - local html, html_path = page.build(filepath) + local filemeta = model.get(filepath) + local html, html_path = page.build(filepath, filemeta) local feed_xml, feed_xml_path if args['export'] then @@ -63,7 +70,7 @@ if args['pipeline'] then -- If filepath is an index -- Then build and export his feed if file.is_index(filepath) then - feed_xml, feed_xml_path = feed.build(filepath) + feed_xml, feed_xml_path = feed.build(filepath, filemeta) feed.export(feed_xml_path, feed_xml) end @@ -80,3 +87,42 @@ if args['pipeline'] then return end + +if args['make'] then + local config + local content + + if file.exists('config.lua') then + -- Add the currentdir to the package.path + package.path = package.path .. ';'.. lfs.currentdir() ..'/?.lua' + -- Set config.lua in a table + config = require 'config' + -- Absolute path to the content directory + contentdir = lfs.currentdir() .. '/' .. config.paths.content + + for filepath in dirtree.get(contentdir) do + if file.is_markdown(filepath) then + local filemeta = model.get(filepath, config) + local html, html_path = page.build(filepath, filemeta) + local feed_xml, feed_xml_path + + if args['export'] then + page.export(html_path, html) + + -- If filepath is an index + -- Then build and export his feed + if file.is_index(filepath) then + feed_xml, feed_xml_path = feed.build(filepath, filemeta) + feed.export(feed_xml_path, feed_xml) + end + + -- Copy assets to the public_html/ folder + assets.export(filepath) + end + end + end + else + print('There is no "config.lua" here.') + os.exit() + end +end