From ed586b4fe54c9a3125cd7050f79a1b0d441644be Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 2 Sep 2024 23:46:25 +0200 Subject: Script can now be configured to filter by pattern and/or direct excludes list --- generate-index.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'generate-index.lua') diff --git a/generate-index.lua b/generate-index.lua index b079434..1ab4db4 100755 --- a/generate-index.lua +++ b/generate-index.lua @@ -1,7 +1,8 @@ #!/usr/bin/env lua -local pretty = require"pl.pretty" +local config = require"pl.config" local dir = require"pl.dir" local gumbo = require"gumbo" +local tablex = require"pl.tablex" local function parse (stamp) @@ -23,16 +24,23 @@ local function describe (date) end +config = config.read(arg[1] or "huh.conf") or {} +config.excludes = tablex.makeset(config.excludes or {}) + + +local function matches (str) + if config.pattern then + return str:match(config.pattern) + end + return str +end + + local pages = dir.getfiles(".", "*.html") local takeaways = { ["published-on"] = "published", ["last-modified-on"] = "modified", } -local excludes = { - ["index.html"] = true, - ["graveyard_of_the_drawings.html"] = true, - ["plop.html"] = true, -} local posts = {} for _, filename in pairs(pages) do local document = gumbo.parseFile(filename) @@ -49,7 +57,7 @@ for _, filename in pairs(pages) do end end end - if properties.filename:match"^[^_]" and not excludes[properties.filename] then + if matches(properties.filename) and not config.excludes[properties.filename] then table.insert(posts, properties) end end -- cgit v1.1