You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.2 KiB
90 lines
3.2 KiB
-- @module model
|
|
local model = {}
|
|
--
|
|
local etlua = require 'etlua'
|
|
local lfs = require 'lfs' -- luafilesystem
|
|
local lume = require 'satelito.lib.lume.lume'
|
|
local dirtree = require 'satelito.dirtree'
|
|
local file = require 'satelito.file'
|
|
local list = require 'satelito.list'
|
|
local markdown = require 'discount' -- lua-discount
|
|
local template = require 'satelito.template'
|
|
|
|
function model.set(filepath, config, contentdir)
|
|
local pagemeta = file.get_metafile(filepath) or {}
|
|
local time_created
|
|
|
|
-- If required properties are nil
|
|
pagemeta.title = pagemeta.title or file.get_basename(filepath):match('(.+)%..*')
|
|
pagemeta.date = pagemeta.date or os.date('%Y-%m-%d', lfs.attributes(filepath).change)
|
|
pagemeta.datetime = pagemeta.datetime or os.date('%H:%M:%S', lfs.attributes(filepath).change)
|
|
|
|
-- Path properties
|
|
pagemeta.contentdir = contentdir
|
|
pagemeta.path = filepath
|
|
pagemeta.relpath = file.get_relpath(filepath, contentdir)
|
|
pagemeta.reldir = pagemeta.relpath:match("(.*/)")
|
|
|
|
-- Link properties
|
|
pagemeta.rellink = file.get_rellink(filepath, contentdir)
|
|
pagemeta.rellinkdir = '/'.. (pagemeta.reldir ~= nil and pagemeta.reldir or '')
|
|
pagemeta.permalink = file.get_permalink(filepath, contentdir, config.siteurl)
|
|
pagemeta.exportlink = file.get_exportlink(filepath, contentdir, config.paths.public_html)
|
|
pagemeta.dirlink = file.get_permalink(filepath, contentdir, config.siteurl):match("(.*/)")
|
|
|
|
-- Time properties
|
|
time_created = (pagemeta.date..pagemeta.datetime):gsub('%W','')
|
|
|
|
pagemeta.time_created = time_created
|
|
pagemeta.time_modification = lfs.attributes(filepath).modification
|
|
pagemeta.time_modified_child = file.get_lastmodified(lume.array(dirtree.get(file.get_dirname(filepath))))
|
|
|
|
-- Unique page ID for the Atom feed
|
|
pagemeta.id = 'tag:' .. config.siteurl:match('^%w+://([^/]+)') .. ',' .. pagemeta.date .. ':' .. pagemeta.rellink
|
|
pagemeta.idorder = pagemeta.rellinkdir .. time_created
|
|
|
|
-- HTML content
|
|
if file.is_markdown(filepath) then
|
|
pagemeta.content = markdown(file.read(filepath))
|
|
elseif file.is_html(filepath) then
|
|
pagemeta.content = file.read(filepath)
|
|
end
|
|
|
|
-- List (and Feed)
|
|
if file.is_index(filepath) and pagemeta.list ~= false then
|
|
pagemeta.list = file.get_collection(filepath, contentdir)
|
|
end
|
|
|
|
-- Archives
|
|
if pagemeta.archives then
|
|
pagemeta.archives_children = list.get_archives(contentdir)
|
|
end
|
|
|
|
-- Tags
|
|
if pagemeta.tags then
|
|
pagemeta.tags_children = list.get_tags(contentdir)
|
|
end
|
|
|
|
-- Change the language for a specific content
|
|
pagemeta.language = pagemeta.language or config.language
|
|
|
|
-- Templates
|
|
pagemeta.template = pagemeta.template or pagemeta.posttype or 'default'
|
|
pagemeta.layout = pagemeta.layout or 'layout'
|
|
pagemeta.head = pagemeta.head or 'head'
|
|
pagemeta.navigation = pagemeta.navigation or 'navigation'
|
|
pagemeta.footer = pagemeta.footer or 'footer'
|
|
pagemeta.feed = pagemeta.feed or 'feed.xml'
|
|
|
|
-- Include a partial template and compile it
|
|
-- @usage <%- include("test-partial") %>
|
|
pagemeta.include = function(templatename)
|
|
local inc = etlua.compile(file.read(template.find(config.templates, templatename)))
|
|
|
|
return inc(pagemeta)
|
|
end
|
|
|
|
return lume.extend({}, config, pagemeta)
|
|
end
|
|
|
|
return model
|
|
|