satelito

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

commit be3a35985c1f1cc5cafbab58cc4c7800db46b90c
parent b23122a992a8190aba0cb05684e59144f4814d99
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sun,  3 Oct 2021 13:58:54 -0400

Add the mecanism to make a tags page

Diffstat:
Msatelito/list.lua | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Msatelito/model.lua | 8++++++--
2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/satelito/list.lua b/satelito/list.lua @@ -6,6 +6,7 @@ local file = require 'satelito.file' local inspect = require 'inspect' local lume = require 'satelito.lib.lume.lume' +-- Children function list.get_children(children_list, sitemap, asc) local children @@ -30,6 +31,7 @@ function list.get_children(children_list, sitemap, asc) return children end +-- Archives function list.get_archives(contentdir) local archives_table = {} @@ -80,4 +82,52 @@ function list.get_archives(contentdir) return archives_table end +-- Tags +function list.get_tags(contentdir) + local tags_table = {} + + -- Insert all the keywords as key of an empty subtable + 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.keywords ~= nil then + for _, keyword in pairs(file.get_metafile(filepath).keywords) do + if keyword ~= '' then + tags_table[keyword] = {} + end + end + end + end + end + + -- After insert relative links in each keyword's 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.keywords ~= nil then + for _, keyword in pairs(file.get_metafile(filepath).keywords) do + if tags_table[keyword] then + local tags_info = { + title = metafile.title, + rellink = file.get_rellink(filepath, contentdir) + } + + table.insert(tags_table[keyword], tags_info) + end + end + end + end + end + + return tags_table +end + return list diff --git a/satelito/model.lua b/satelito/model.lua @@ -7,7 +7,6 @@ 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 {} @@ -52,7 +51,7 @@ function model.set(filepath, config, contentdir) pagemeta.content = file.read(filepath) end - -- List and Feed + -- List (and Feed) if file.is_index(filepath) and pagemeta.list ~= false then pagemeta.list = file.get_collection(filepath, contentdir) end @@ -62,6 +61,11 @@ function model.set(filepath, config, contentdir) pagemeta.archives_children = list.get_archives(contentdir) end + -- Tags + if pagemeta.tags then + pagemeta.tags_children = list.get_tags(contentdir) + end + -- Templates pagemeta.template = pagemeta.template or pagemeta.posttype or 'default' pagemeta.layout = pagemeta.layout or 'layout'