satelito

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

assets.lua (1006B)


      1 -- @module assets
      2 local assets = {}
      3 --
      4 local file = require 'satelito.file'
      5 local lfs = require 'lfs' -- luafilesystem
      6 local lume = require 'satelito.lib.lume.lume'
      7 local mimetypes = require 'mimetypes'
      8 
      9 function assets.export(filemeta)
     10   local mtypes = filemeta.mimetypes
     11   local siblings = lume.array(lfs.dir(file.get_dirname(filemeta.paths.content..filemeta.relpath)))
     12   local function is_in_mimetypes(f)
     13     return lume.any(mtypes, function(mtype) return mtype == mimetypes.guess(f) end)
     14   end
     15 
     16   for _, sibling in ipairs(siblings) do
     17     if is_in_mimetypes(sibling) then
     18       local source = file.get_dirname(filemeta.paths.content..filemeta.relpath)..sibling
     19       local target = file.get_dirname(filemeta.exportlink) .. sibling
     20 
     21       if not lfs.attributes(target)
     22         or lfs.attributes(source).modification > lfs.attributes(target).modification
     23       then
     24         print(source, target)
     25 
     26         os.execute('cp ' .. source ..  ' ' .. target)
     27       end
     28     end
     29   end
     30 
     31   return
     32 end
     33 
     34 return assets