satelito

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

commit f31d153265a19f3d37ceaa7ba37e398fe7461d0b
parent f992ac006b116f005825ffaafebcf5c35ff0d499
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Fri,  9 Apr 2021 14:34:17 -0400

Refactor the assets module

Diffstat:
Msatelito/assets.lua | 24+++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/satelito/assets.lua b/satelito/assets.lua @@ -5,31 +5,25 @@ local file = require 'satelito.file' local lfs = require 'lfs' -- luafilesystem local lume = require 'satelito.lib.lume.lume' local mimetypes = require 'mimetypes' -local site = require 'satelito.site' -function assets.export(filepath) - local config = assert(site.set_config(filepath), "Sorry, the site configuration can't be set") - local mtypes = assert(config.mimetypes) - local siblings = assert(lume.array(lfs.dir(file.get_dirname(filepath)))) +function assets.export(filemeta) + local mtypes = filemeta.mimetypes + local siblings = lume.array(lfs.dir(file.get_dirname(filemeta.paths.content..filemeta.relpath))) local function is_in_mimetypes(f) return lume.any(mtypes, function(mtype) return mtype == mimetypes.guess(f) end) end for _, sibling in ipairs(siblings) do if is_in_mimetypes(sibling) then - local content_dir = site.get_root(filepath) .. '/' .. config.paths.content - local public_dir = site.get_root(filepath) .. '/' .. config.paths.public_html - local src_dir = file.get_dirname(filepath) - local src_path = src_dir .. sibling - local dst_dir = public_dir .. file.get_dirname(file.get_relpath(filepath, content_dir)) - local dst_path = dst_dir .. sibling + local source = file.get_dirname(filemeta.paths.content..filemeta.relpath)..sibling + local target = file.get_dirname(filemeta.exportlink) .. sibling - if not lfs.attributes(dst_path) - or lfs.attributes(src_path).modification > lfs.attributes(dst_path).modification + if not lfs.attributes(target) + or lfs.attributes(source).modification > lfs.attributes(target).modification then - print(src_path, dst_path) + print(source, target) - os.execute('cp ' .. src_path .. ' ' .. dst_path) + os.execute('cp ' .. source .. ' ' .. target) end end end