| 85 | | function get_entries(dir, ext) |
| 86 | | local ret = List.new() |
| 87 | | local tf = os.tmpname() |
| 88 | | -- ruby++ |
| 89 | | os.execute('ruby -rpathname -e "Pathname.glob(%|'..dir..'/**/*'..ext..'|){|f|puts %|#{f.mtime.to_i} #{f}|}" > ' .. tf) |
| 90 | | for line in io.lines(tf) do |
| 91 | | local time, filename = string.match(line, "(%d+) (.+)") |
| 92 | | local e = Entry.new(filename, tonumber(time, 10)) |
| 93 | | e.name = string.gsub(string.gsub(filename, "%.%w+$", ""), "^"..dir, "") |
| 94 | | ret:push(e) |
| 95 | | end |
| 96 | | return ret |
| 97 | | end |
| | 89 | run = function (self) |
| | 90 | path_info = os.getenv("PATH_INFO") or "/" |
| | 91 | flavour = string.match(path_info, "(%..+)$") or ".html" |
| | 92 | path_info = string.gsub(path_info, "%..+$", "") |
| | 93 | path_info = string.gsub(path_info, "index$", "") |
| | 99 | local year, month, day |
| | 100 | for i, v in ipairs({"^/(%d+)/(%d+)/(%d+)", "^/(%d+)/(%d+)", "^/(%d+)"}) do |
| | 101 | year, month, day = string.match(path_info, v) |
| | 102 | if year then break end |
| | 103 | end |
| | 104 | if year then |
| | 105 | entries = entries:select(function (e) |
| | 106 | local ret = true |
| | 107 | for i, v in ipairs({{m = "%Y", v = year}, {m = "%m", v = month}, {m = "%d", v = day}}) do |
| | 108 | if v.v and not(os.date(v.m, e.time) == v.v) then |
| | 109 | ret = false |
| | 110 | end |
| | 111 | end |
| | 112 | return ret |
| | 113 | end) |
| | 114 | else |
| | 115 | entries = entries:select(function (e) |
| | 116 | return string.match(e.name, "^"..path_info) |
| | 117 | end) |
| | 118 | end |
| | 119 | |
| | 120 | ELua.run("template"..flavour, { |
| | 121 | title = self.config.title, |
| | 122 | home = os.getenv("SCRIPT_NAME"), |
| | 123 | server = "http://" .. tostring(os.getenv("SERVER_NAME")), |
| | 124 | entries = entries, |
| | 125 | debugObj = "aaa", |
| | 126 | }) |
| | 127 | |
| | 128 | end, |
| | 129 | |
| | 130 | get_entries = function (dir, ext) |
| | 131 | local ret = List.new() |
| | 132 | local tf = os.tmpname() |
| | 133 | -- ruby++ |
| | 134 | os.execute('ruby -rpathname -e "Pathname.glob(%|'..dir..'/**/*'..ext..'|){|f|puts %|#{f.mtime.to_i} #{f}|}" > ' .. tf) |
| | 135 | for line in io.lines(tf) do |
| | 136 | local time, filename = string.match(line, "(%d+) (.+)") |
| | 137 | local e = Entry.new(filename, tonumber(time, 10)) |
| | 138 | e.name = string.gsub(string.gsub(filename, "%.%w+$", ""), "^"..dir, "") |
| | 139 | ret:push(e) |
| | 140 | end |
| | 141 | return ret |
| | 142 | end, |
| | 143 | } |
| | 144 | |
| | 145 | Bluasxom.new({ |
| | 146 | title = "Bluasxom", |
| | 147 | author = "jitensya", |
| | 148 | dataext = ".txt", |
| | 149 | datadir = "data", |
| | 150 | }):run() |
| | 151 | |