diff options
author | Aki <please@ignore.pl> | 2024-09-03 21:35:27 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-09-03 21:36:47 +0200 |
commit | 84d611c78ac65113ed8cc7838994669de270d4d0 (patch) | |
tree | 5832af26d8c4bfe0c48773e2dc69f3ecb1da52ef /generate-index.lua | |
parent | ed586b4fe54c9a3125cd7050f79a1b0d441644be (diff) | |
download | huh-master.zip huh-master.tar.gz huh-master.tar.bz2 |
Diffstat (limited to 'generate-index.lua')
-rwxr-xr-x | generate-index.lua | 70 |
1 files changed, 5 insertions, 65 deletions
diff --git a/generate-index.lua b/generate-index.lua index 1ab4db4..b53beb2 100755 --- a/generate-index.lua +++ b/generate-index.lua @@ -1,78 +1,18 @@ #!/usr/bin/env lua -local config = require"pl.config" -local dir = require"pl.dir" -local gumbo = require"gumbo" -local tablex = require"pl.tablex" - - -local function parse (stamp) - local year, month, day, hour, min, sec = stamp:match"(%d+)-(%d?%d)-(%d?%d)T(%d?%d):(%d?%d):(%d?%d)" - return { - year = tonumber(year), - month = tonumber(month), - day = tonumber(day), - hour = tonumber(hour), - min = tonumber(min), - sec = tonumber(sec), - } -end - - -local function describe (date) - -- strftime(3) still does not support printing day of month without leading zero or space. - return string.format("%d %s", date.day, os.date("%B", os.time(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 posts = {} -for _, filename in pairs(pages) do - local document = gumbo.parseFile(filename) - local metas = document:getElementsByTagName"meta" - local properties = {title=document.title, filename=filename:sub(3), published=""} - for _, meta in ipairs(metas) do - local take = nil - for _, attribute in ipairs(meta.attributes) do - if attribute.name == "name" then - take = takeaways[attribute.value] - end - if take and attribute.name == "content" then - properties[take] = attribute.value - end - end - end - if matches(properties.filename) and not config.excludes[properties.filename] then - table.insert(posts, properties) - end -end -table.sort(posts, function (lhs, rhs) return lhs.published > rhs.published end) +local datetime = require"huh.datetime" +local config = require"huh.config".load(arg[1]) +local posts = require"huh.blog".posts(config) print[[<table class="index">]] local year = nil local previous = nil for _, page in pairs(posts) do - local date = parse(page.published) + local date = datetime.parse(page.published) if date and year ~= date.year then year = date.year previous = nil print(string.format("<tr><td><b>%d</b><td><td>", year)) end - date = describe(date) + date = datetime.describe(date) if date == previous then date = "" else |