local dir = require"pl.dir" local gumbo = require"gumbo" local blog = {} local takeaways = { ["published-on"] = "published", ["last-modified-on"] = "modified", } function blog.posts (config) local pages = dir.getfiles(".", "*.html") 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 config:check(properties.filename) then table.insert(posts, properties) end end table.sort(posts, function (lhs, rhs) return lhs.published > rhs.published end) return posts end return blog