summaryrefslogtreecommitdiff
path: root/maker
diff options
context:
space:
mode:
Diffstat (limited to 'maker')
-rwxr-xr-xmaker134
1 files changed, 98 insertions, 36 deletions
diff --git a/maker b/maker
index a00efdb..412dc10 100755
--- a/maker
+++ b/maker
@@ -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,36 +117,62 @@ for i, page in ipairs(config.static) do
build(path, page.template, data)
end
-local archive = "find %s -perm /o+r -readable -not -iname '*~' -not -path '%s' -type d | sort -n"
-local files = {}
-for raw in io.popen(archive:format(config.src, config.src)):read("*a"):gmatch("[^\n]+") do
- local original = lfs.currentdir()
- lfs.chdir(raw)
-
- local page = {}
- page.site = config
- page.articles = {}
-
- local finder = "find . -perm /o+r -readable -not -iname '*~' -type f | sort -rn"
- local nposts = 0
- for file in io.popen(finder:format(config.src)):read("*a"):gmatch("[^\n]+") do
- local data = lupin.transform(file, "later", false, "full")
- local slug = posix.basename(file):gsub(".txt$", "")
-
- data.path = posix.dirname(file):gsub("^" .. config.src, "")
- data.url = config.base .. data.path .. "/" .. slug
- if config.extension then
- data.url = data.url .. config.extension
+-- 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
- nposts = nposts + 1
- table.insert(page.articles, data)
+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
- lfs.chdir(original)
- if nposts > 0 then
- local apath = raw:gsub("^" .. config.src, "")
- local path = config.www .. "/" .. apath .. "/index.html"
- build(path, "index", page)
+ if daily[i + 1] then
+ dir.nextarchive = daily[i + 1]
end
+ build(dir.path, dir.template, dir)
end