summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlupin.lua50
1 files changed, 31 insertions, 19 deletions
diff --git a/lupin.lua b/lupin.lua
index f629d04..a1c31f1 100755
--- a/lupin.lua
+++ b/lupin.lua
@@ -8,14 +8,36 @@ require 'corz'
CACHE = "/home/bie/tmp.db"
cache = tokyocabinet.bdbnew()
+cache:open(CACHE, cache.OWRITER + cache.OREADER)
+
+function userurl(basename, basecache, home, fallback)
+ local path = ("/home/%s/%s"):format(home, basename)
+ local cache = ("/srv/www/users/%s"):format(basecache)
+ if not posix.stat(path) then return fallback end
+ if not posix.stat(cache) then
+ posix.unlink(cache)
+ posix.link(path, cache, true)
+ end
+ return ("https://intern.radionova.no/users/%s"):format(basecache)
+end
+
+function userfile(basename, home, fallback)
+ local path = ("/home/%s/%s"):format(home, basename)
+ local ok, data = pcall(function()
+ return io.open(path):read("*l")
+ end)
+ if ok then
+ return data:gsub("[\r\n]*", "")
+ else
+ return fallback
+ end
+end
function oembed(endpoint, id)
- cache:open(CACHE, cache.OWRITER + cache.OREADER)
local url = endpoint .. id
local cached = cache:get(id)
if cached then
local data = json.decode(cached)
- cache:close()
return data.html
end
@@ -25,9 +47,8 @@ function oembed(endpoint, id)
end}:perform()
if result:getinfo(http.INFO_RESPONSE_CODE) == 200 then
cache:put(id, body)
- cache:close()
local data = json.decode(body)
- return data.html
+ return "<div class=embed>" .. data.html .. "</div>"
else
return ("<b>Klarte ikke embedde %s :(</b>"):format(url)
end
@@ -54,7 +75,7 @@ function twitch(id)
end
function instagram(id)
- return oembed("https://api.instagram.com/oembed?url=", id)
+ return oembed("https://api.instagram.com/oembed/?url=", id)
end
function flickr(id)
@@ -319,23 +340,14 @@ function lupin.transform(path, format, env, mode)
if path ~= "-" then
local stat = posix.stat(path)
local pwd = posix.getpasswd(stat.uid)
+
data.author = pwd.name
+ data.authorname = userfile("navn", data.author, data.author)
+
data.group = posix.getgroup(stat.gid).name
- -- if data.published then
- -- data.date = os.date("%A %d. %B %Y, kl. %H.%M", data.published)
- -- else
- -- local root = "/srv/www/happiest.place/tears/artikler"
- -- y, m, d = file:match(root .. "/(.*)/(.*)/(.*)/(.*)")
- -- data.date = ("%s/%s/%s"):format(y, m, d)
- -- end
- -- if posix.stat(pwd.dir .. "/portrait.jpg") then
- if posix.stat(("/srv/www/users/%s.jpg"):format(data.author)) then
- data.portrait = ("/users/%s.jpg"):format(data.author)
- end
+ data.groupname = userfile("navn", data.group, data.group)
- if posix.stat(pwd.dir .. "/.name") then
- data.author = io.open(pwd.dir .. "/.name"):read("*l")
- end
+ data.portrait = userurl("selfie.jpg", data.author .. ".jpg", data.author)
end
if format == "later" then