diff options
Diffstat (limited to 'maker')
-rwxr-xr-x | maker | 114 |
1 files changed, 104 insertions, 10 deletions
@@ -51,23 +51,59 @@ for n, src in ipairs(files) do end end +function dirtodata(dir, files) + local data = {} + data.slug = dir:gsub("^" .. config.src, ""):gsub("^/", "") + data.path = config.www .. "/" .. data.slug .. "/index.html" + data.articles = files + data.url = config.base .. "/" .. data.slug + if data.slug:match("^%d+$") then + data.collection = "year" + data.template = "yearly" + elseif data.slug:match("^%d+/%d+$") then + data.collection = "month" + data.template = "archive" + else + data.collection = "day" + data.template = "archive" + end + return data +end + +function filetodata(file) + local data = lupin.transform(file, "later", false, "full") + data.slug = posix.basename(file):gsub(".txt$", "") + data.path = posix.dirname(file):gsub("^" .. config.src, "") + data.url = config.base .. "/" .. data.path .. "/" .. data.slug + data.archive = posix.dirname(posix.dirname(file)) + if config.extension then + data.url = data.url .. config.extension + end + return data +end + local path = config.www .. "/" .. "index.html" local page = {} page.site = config page.articles = {} -for n=1,8 do +local more = false +for n=1,6 do if files[n] then - local data - local data = lupin.transform(files[n], "later", false, "full") - local slug = posix.basename(files[n]):gsub(".txt$", "") - data.path = posix.dirname(files[n]):gsub("^" .. config.src, "") - data.url = config.base .. "/" .. data.path .. "/" .. slug - if config.extension then - data.url = data.url .. config.extension - end + local data = filetodata(files[n]) table.insert(page.articles, data) + if files[n + 1] then + more = files[n + 1] + else + more = false + end + else + more = false end end +if more then + page.next = filetodata(more) +end +build(path, "index", page) for i, page in ipairs(config.static) do local path = config.www .. "/" .. page.path @@ -81,4 +117,62 @@ for i, page in ipairs(config.static) do build(path, page.template, data) end -build(path, "index", page) +-- archive time! +local finder = "find %s -perm /o+r -readable -not -iname '*~' -type d | sort -n" + +local yearly = {} +local monthly = {} +local daily = {} + +for dir in io.popen(finder:format(config.src)):read("*a"):gmatch("[^\n]+") do + if dir ~= config.src then + local finder = "find %s -perm /o+r -readable -not -iname '*~' -type f | sort -rn" + local files = {} + for file in io.popen(finder:format(dir)):read("*a"):gmatch("[^\n]+") do + table.insert(files, filetodata(file)) + end + if #files > 0 then + local data = dirtodata(dir, files) + if data.collection == "year" then + table.insert(yearly, data) + elseif data.collection == "month" then + table.insert(monthly, data) + elseif data.collection == "day" then + table.insert(daily, data) + else + print(data.collection) + end + end + end +end + +for i,dir in ipairs(yearly) do + if i > 1 then + dir.prevarchive = yearly[i - 1] + end + if yearly[i + 1] then + dir.nextarchive = yearly[i + 1] + end + build(dir.path, dir.template, dir) +end + +for i,dir in ipairs(monthly) do + if i > 1 then + dir.prevarchive = monthly[i - 1] + end + if monthly[i + 1] then + dir.nextarchive = monthly[i + 1] + end + build(dir.path, dir.template, dir) +end + +for i,dir in ipairs(daily) do + if i > 1 then + dir.prevarchive = daily[i - 1] + end + if daily[i + 1] then + dir.nextarchive = daily[i + 1] + end + build(dir.path, dir.template, dir) +end + |