Static site generator made with Lua script.
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.

35 lines
1.0 KiB

-- @module assets
local assets = {}
--
local file = require 'satelito.file'
local lfs = require 'lfs' -- luafilesystem
local lume = require 'satelito.lib.lume.lume'
local mimetypes = require 'mimetypes'
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 i = 1, #siblings do
if is_in_mimetypes(siblings[i]) then
local source = file.get_dirname(filemeta.paths.content..filemeta.relpath)..siblings[i]
local target = file.get_dirname(filemeta.exportlink)..siblings[i]
if not lfs.attributes(target)
or lfs.attributes(source).modification > lfs.attributes(target).modification
then
print('=> Moving assets ...')
print('====> '..source..' => '..target)
os.execute('cp ' .. source .. ' ' .. target)
end
end
end
return
end
return assets