satelito

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

commit 667df16418b8ee5a19239b5b4b6eb618b724a7d9
parent 5392ceceb7eaacab97ae1f08319f40ab1c3cf06e
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sat,  2 Oct 2021 16:38:41 -0400

Add a mecanism to create archives page

Diffstat:
Msatelito/list.lua | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Msatelito/model.lua | 7+++++++
2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/satelito/list.lua b/satelito/list.lua @@ -1,6 +1,9 @@ -- @module list local list = {} -- +local dirtree = require 'satelito.dirtree' +local file = require 'satelito.file' +local inspect = require 'inspect' local lume = require 'satelito.lib.lume.lume' function list.get_children(children_list, sitemap, asc) @@ -27,4 +30,54 @@ function list.get_children(children_list, sitemap, asc) return children end +function list.get_archives(contentdir) + local archives_table = {} + + for filepath in dirtree.get(contentdir) do + if file.is_markdown(filepath) + or file.is_html(filepath) + and file.get_metafile(filepath) + then + local metafile = file.get_metafile(filepath) + + if metafile.date ~= '0000-00-00' then + local year = string.sub(metafile.date, 1, 4) + local month = string.sub(metafile.date, 6, 7) + + if archives_table[year] then + archives_table[year][month] = {} + else + archives_table[year] = { + [month] = {} + } + end + end + end + end + + for filepath in dirtree.get(contentdir) do + if file.is_markdown(filepath) + or file.is_html(filepath) + and file.get_metafile(filepath) + then + local metafile = file.get_metafile(filepath) + + if metafile.date ~= '0000-00-00' then + local year = string.sub(metafile.date, 1, 4) + local month = string.sub(metafile.date, 6, 7) + local day = string.sub(metafile.date, 9, 10) + local archive_info = { + day = day, + rellink = file.get_rellink(filepath, contentdir), + title = metafile.title + } + + table.insert(archives_table[year][month], archive_info) + end + end + end + + return archives_table +end + return list diff --git a/satelito/model.lua b/satelito/model.lua @@ -5,7 +5,9 @@ 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 inspect = require 'inspect' -- lua-discount function model.set(filepath, config, contentdir) local pagemeta = file.get_metafile(filepath) or {} @@ -55,6 +57,11 @@ function model.set(filepath, config, contentdir) pagemeta.list = file.get_collection(filepath, contentdir) end + -- Archives + if pagemeta.archives then + pagemeta.archives_children = list.get_archives(contentdir) + end + -- Templates pagemeta.template = pagemeta.template or pagemeta.posttype or 'default' pagemeta.layout = pagemeta.layout or 'layout'