satelito

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

page.lua (1417B)


      1 -- @module page
      2 local page = {}
      3 --
      4 local etlua = require 'etlua'
      5 local lume = require 'satelito.lib.lume.lume'
      6 local file = require 'satelito.file'
      7 local template = require 'satelito.template'
      8 
      9 --- Build a page from markdown/lua to HTML
     10 -- @name page.make
     11 -- @param filepath a pathname to a markdown file
     12 -- @return a string that is an HTML code block
     13 -- @return a string that is a filepath
     14 
     15 function page.make(filemeta, exportpath)
     16   -- Compile different parts of the page
     17   local head = etlua.compile(file.read(template.find(filemeta.templates, filemeta.head)))
     18   local navigation = etlua.compile(file.read(template.find(filemeta.templates, filemeta.navigation)))
     19   local post = etlua.compile(file.read(template.find(filemeta.templates, filemeta.template)))
     20   local footer = etlua.compile(file.read(template.find(filemeta.templates, filemeta.footer)))
     21   local layout = etlua.compile(file.read(template.find(filemeta.templates, filemeta.layout)))
     22 
     23   -- Then put them all together
     24   local html = layout(
     25     lume.extend({},
     26       filemeta,
     27       {post = post(lume.extend({}, filemeta))},
     28       {head = head(lume.extend({}, filemeta))},
     29       {navigation = navigation(lume.extend({}, filemeta))},
     30       {footer = footer(lume.extend({}, filemeta))}
     31     )
     32   )
     33   -- Get the target location of the page
     34   local html_path = exportpath ~= nil and exportpath or filemeta.exportlink
     35 
     36   return html, html_path
     37 end
     38 
     39 return page