satelito

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

commit c073e5003df5dd7f4d2ac4577e09c6653266ca3e
parent 2772719d5267c2d401534574aa42d85555067039
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Fri,  9 Apr 2021 14:39:06 -0400

Refactor the model module

Diffstat:
Msatelito/model.lua | 39++-------------------------------------
1 file changed, 2 insertions(+), 37 deletions(-)

diff --git a/satelito/model.lua b/satelito/model.lua @@ -5,8 +5,6 @@ local lfs = require 'lfs' -- luafilesystem local lume = require 'satelito.lib.lume.lume' local dirtree = require 'satelito.dirtree' local file = require 'satelito.file' -local site = require 'satelito.site' -local inspect = require 'inspect' local markdown = require 'discount' -- lua-discount function model.set(filepath, config, contentdir) @@ -47,7 +45,7 @@ function model.set(filepath, config, contentdir) -- HTML content pagemeta.content = markdown(file.read(filepath)) - -- List + -- List and Feed if file.is_index(filepath) and pagemeta.list ~= false then pagemeta.list = file.get_collection(filepath, contentdir) end @@ -57,42 +55,9 @@ function model.set(filepath, config, contentdir) pagemeta.layout = pagemeta.layout or 'layout' pagemeta.head = pagemeta.head or 'head' pagemeta.nav = pagemeta.nav or 'navigation' + pagemeta.feed = pagemeta.feed or 'feed.xml' return lume.extend({}, pagemeta, config) end -function model.get(filepath, siteconfig) - -- The site config.lua file - local config = (siteconfig or site.set_config(filepath)) - local contentdir = assert(site.get_root(filepath) .. '/' .. config.paths.content) - local metafile = file.get_metafile(filepath) - local rellink = file.get_rellink(filepath, contentdir) - local id = assert('tag:' .. config.domainname .. ',' .. metafile.date .. ':' .. rellink) - - -- If there's no parameter file for the markdown - -- Then set the minimum from the markdown file itself - if next(metafile) == nil then - print(filepath:match('(.+)%..*') .. '.lua' .. ' is missing.') - print('You should create it to be able to add metadata.') - - metafile['title'] = file.get_basename(filepath):match('(.+)%..*') - metafile['date'] = os.date('%Y-%m-%d', lfs.attributes(filepath).change) - metafile['datetime'] = os.date('%H:%M:%S', lfs.attributes(filepath).change) - end - - - return lume.extend({}, - config, - metafile, - {relpath = file.get_relpath(filepath, contentdir)}, - {rellink = file.get_rellink(filepath, contentdir)}, - {permalink = file.get_permalink(filepath, contentdir, config.url)}, - {dirlink = file.get_permalink(filepath, contentdir, config.url):match("(.*/)")}, - {time_created = (metafile.date..metafile.datetime):gsub('%W','')}, - {time_modification = lfs.attributes(filepath).modification}, - {time_modified_child = file.get_lastmodified(lume.array(dirtree.get(file.get_dirname(filepath))))}, - {id = id} - ) -end - return model