satelito

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

commit 8f0f100e4456be5572d3142a927e1051c7ab3d39
parent 66c25b889b12f316abcd741e1bfaa325fcd89f0a
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Tue, 15 Mar 2022 15:39:24 -0400

Put the templates in the config table

Diffstat:
Msatelito/feed.lua | 4++--
Msatelito/init.lua | 40++++++++++++++++++++++------------------
Msatelito/model.lua | 4+---
Msatelito/page.lua | 12++++++------
Msatelito/site.lua | 26+++++++++++++++++---------
5 files changed, 48 insertions(+), 38 deletions(-)

diff --git a/satelito/feed.lua b/satelito/feed.lua @@ -6,8 +6,8 @@ local lume = require 'satelito.lib.lume.lume' local file = require 'satelito.file' local template = require 'satelito.template' -function feed.make(filemeta, templates) - local _feed = etlua.compile(file.read(template.find(templates, filemeta.feed))) +function feed.make(filemeta) + local _feed = etlua.compile(file.read(template.find(filemeta.templates, filemeta.feed))) local feed_xml = _feed(lume.extend({}, filemeta)) local feed_xml_path = filemeta.exportlink:match('(.+)%..*')..'.xml' diff --git a/satelito/init.lua b/satelito/init.lua @@ -2,7 +2,6 @@ -- local argparse = require 'argparse' local lfs = require 'lfs' -local inspect = require 'inspect' -- local lume = require 'satelito.lib.lume.lume' local model = require 'satelito.model' @@ -102,8 +101,14 @@ if args['pipe'] 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, config, contentdir) + local meta = model.set(filepath, lume.extend(config, {templates = templates}), contentdir) -- Add the meta of the file into the sitemap table if lume.count(sitemap) == 0 then @@ -117,15 +122,11 @@ if args['pipe'] then print('=> '..lume.count(sitemap)..' content found') - -- Array of templates - print('=> Fetching the templates ...') - templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates)) - print('=> Making the web site ...') table.sort(sitemap, function(a, b) return a.idorder > b.idorder end) - return site.make(sitemap, templates, args['export'], timestart, config) + return site.make(sitemap, args['export'], timestart) end -- Make command @@ -149,33 +150,36 @@ if args['make'] then -- Absolute path to the 'content/' directory local contentdir = lfs.currentdir() .. '/' .. config.paths.content + print('=> Fetching the templates ...') + templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates)) + print('=> Fetching the markdown and HTML content ...') for filepath in dirtree.get(contentdir) do if file.is_markdown(filepath) or file.is_html(filepath) then - local meta = model.set(filepath, config, contentdir) + local meta = model.set(filepath, lume.extend(config, {templates = templates}), contentdir) sitemap[#sitemap+1] = meta end end print('=> '..lume.count(sitemap)..' content found') + print('=> Making the web site ...') - -- Array of templates - print('=> Fetching the templates ...') - templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates)) + -- Sort before make the website + table.sort(sitemap, function(a, b) return a.idorder > b.idorder end) + site.make(sitemap, args['export'], timestart) + + -- Make and export the sitemap.xml if config.sitemapxml and args['export'] then - print('=> Making the sitemap.xml file ...') - local sitemapxml_xml, sitemapxml_xml_path = sitemapxml.make(sitemap, templates, config.paths.public_html) + local sitemapxml_xml, sitemapxml_xml_path = sitemapxml.make( + sitemap, templates, config.paths.public_html + ) file.export(sitemapxml_xml_path, sitemapxml_xml) end - print('=> Making the web site ...') - - table.sort(sitemap, function(a, b) return a.idorder > b.idorder end) - - return site.make(sitemap, templates, args['export'], timestart, config) + return else print('There is no "config.lua" here.') os.exit() diff --git a/satelito/model.lua b/satelito/model.lua @@ -9,12 +9,10 @@ local file = require 'satelito.file' local list = require 'satelito.list' local markdown = require 'discount' -- lua-discount local template = require 'satelito.template' -local inspect = require 'inspect' function model.set(filepath, config, contentdir) local pagemeta = file.get_metafile(filepath) or {} local time_created - local templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates)) -- If required properties are nil pagemeta.title = pagemeta.title or file.get_basename(filepath):match('(.+)%..*') @@ -81,7 +79,7 @@ function model.set(filepath, config, contentdir) -- Include a partial template and compile it -- @usage <%- include("test-partial") %> pagemeta.include = function(templatename) - local inc = etlua.compile(file.read(template.find(templates, templatename))) + local inc = etlua.compile(file.read(template.find(config.templates, templatename))) return inc(pagemeta) end diff --git a/satelito/page.lua b/satelito/page.lua @@ -12,13 +12,13 @@ local template = require 'satelito.template' -- @return a string that is an HTML code block -- @return a string that is a filepath -function page.make(filemeta, templates, exportpath) +function page.make(filemeta, exportpath) -- Compile different parts of the page - local head = etlua.compile(file.read(template.find(templates, filemeta.head))) - local navigation = etlua.compile(file.read(template.find(templates, filemeta.navigation))) - local post = etlua.compile(file.read(template.find(templates, filemeta.template))) - local footer = etlua.compile(file.read(template.find(templates, filemeta.footer))) - local layout = etlua.compile(file.read(template.find(templates, filemeta.layout))) + local head = etlua.compile(file.read(template.find(filemeta.templates, filemeta.head))) + local navigation = etlua.compile(file.read(template.find(filemeta.templates, filemeta.navigation))) + local post = etlua.compile(file.read(template.find(filemeta.templates, filemeta.template))) + local footer = etlua.compile(file.read(template.find(filemeta.templates, filemeta.footer))) + local layout = etlua.compile(file.read(template.find(filemeta.templates, filemeta.layout))) -- Then put them all together local html = layout( diff --git a/satelito/site.lua b/satelito/site.lua @@ -9,7 +9,6 @@ local file = require 'satelito.file' local list = require 'satelito.list' local lume = require 'satelito.lib.lume.lume' local page = require 'satelito.page' -local inspect = require 'inspect' --- From a filepath get the closest 'config.lua' by climbing the -- directory tree @@ -30,15 +29,21 @@ function site.get_config(filepath) end -- Make the site -function site.make(sitemap, templates, export, timestart, config) +function site.make(sitemap, export, timestart) for i = 1, #sitemap do local html, html_path local feed_xml, feed_xml_path local paginated sitemap[i].index = i - 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) + + if sitemap[i].list ~= false and file.is_index(sitemap[i].path) then + sitemap[i].children = list.get_children(sitemap[i].list, sitemap, sitemap[i].asc) + end + + if sitemap[i].collection then + sitemap[i].collection = list.get_collection(sitemap[i].collection, sitemap, sitemap[i].asc) + end if i > 1 then sitemap[i].relprev = sitemap[i-1] @@ -68,11 +73,10 @@ function site.make(sitemap, templates, export, timestart, config) sitemap[i].pagination.current = p -- Make the pagination pages if p == 1 then - html, html_path = page.make(sitemap[i], templates) + html, html_path = page.make(sitemap[i]) else html, html_path = page.make( sitemap[i], - templates, sitemap[i].exportlink:match("(.*/)")..sitemap[i].pagination.prefix..p..'.html' ) end @@ -86,7 +90,7 @@ function site.make(sitemap, templates, export, timestart, config) else -- Make the page - html, html_path = page.make(sitemap[i], templates) + html, html_path = page.make(sitemap[i]) -- Export the page if export then @@ -98,7 +102,7 @@ function site.make(sitemap, templates, export, timestart, config) -- Feed if file.is_index(sitemap[i].relpath) and export then - feed_xml, feed_xml_path = feed.make(sitemap[i], templates) + feed_xml, feed_xml_path = feed.make(sitemap[i]) file.export(feed_xml_path, feed_xml) end @@ -109,7 +113,11 @@ function site.make(sitemap, templates, export, timestart, config) end print('--------------------------------------------------------------------------') - print('Satelito built ' .. lume.count(sitemap) .. ' HTML page(s) in approximately ' .. os.difftime(os.time(), timestart) .. ' second(s).') + print( + 'Satelito built ' + ..lume.count(sitemap)..' HTML page(s) in approximately ' + ..os.difftime(os.time(), timestart)..' second(s).' + ) end return site