2025-02-26 14:39:07 -03:00
|
|
|
---@diagnostic disable:undefined-global
|
|
|
|
|
2025-02-27 13:10:42 -03:00
|
|
|
local wrapper = require "template.wrapper"
|
2025-03-02 00:41:20 -03:00
|
|
|
local error_handler = require "template.error_handler"
|
2025-02-27 13:10:42 -03:00
|
|
|
local phosphor = require "template.phosphor"
|
|
|
|
|
|
|
|
local foppy = require "./foppy"
|
|
|
|
|
|
|
|
return function(data)
|
|
|
|
local blog_name = data.request.params.blog
|
|
|
|
|
|
|
|
-- set a buncha things up
|
2025-03-02 00:41:20 -03:00
|
|
|
local blog = foppy.open(
|
|
|
|
"database/blogs/" .. blog_name .. ".json"
|
|
|
|
)
|
2025-02-27 13:10:42 -03:00
|
|
|
|
|
|
|
-- could find no darn blog!!!
|
|
|
|
if not blog then
|
2025-03-02 00:41:20 -03:00
|
|
|
return error_handler(data, "blog_not_found", "/")
|
2025-02-27 13:10:42 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
-- our little post renderer
|
|
|
|
local function render_post(post)
|
|
|
|
return a {
|
|
|
|
class = "button post",
|
2025-03-02 00:41:20 -03:00
|
|
|
href = "/@" .. blog_name .. "/" .. post.url,
|
2025-02-27 13:10:42 -03:00
|
|
|
h3(post.title),
|
|
|
|
p {
|
|
|
|
class = "timestamp",
|
|
|
|
os.date("%Y-%m-%d %H:%M:%S", post.creation)
|
2025-02-26 14:39:07 -03:00
|
|
|
}
|
2025-02-27 13:10:42 -03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local posts = {}
|
|
|
|
local pinned_posts = {}
|
|
|
|
for _, post in ipairs(blog.index) do
|
|
|
|
if post.pin then
|
|
|
|
table.insert(pinned_posts, post)
|
|
|
|
end
|
|
|
|
table.insert(posts, post)
|
|
|
|
end
|
2025-02-26 14:39:07 -03:00
|
|
|
|
2025-02-27 13:10:42 -03:00
|
|
|
-- return our whole flippin html document
|
2025-03-01 01:12:00 -03:00
|
|
|
return wrapper(data) {
|
2025-02-27 13:10:42 -03:00
|
|
|
-- render header!
|
|
|
|
section {
|
2025-03-03 00:27:45 -03:00
|
|
|
class = "blog-header",
|
|
|
|
|
|
|
|
div {
|
2025-03-02 00:41:20 -03:00
|
|
|
class = "banner",
|
2025-03-03 00:27:45 -03:00
|
|
|
style = blog.banner and "--banner: url('/media/" .. blog.banner .. "')" or ""
|
|
|
|
},
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
class = "title",
|
|
|
|
blog.name,
|
|
|
|
a {
|
|
|
|
class = "handle",
|
|
|
|
href = "/@" .. blog_name,
|
|
|
|
" (@" .. blog_name .. ")"
|
|
|
|
}
|
2025-03-02 00:41:20 -03:00
|
|
|
},
|
2025-03-03 00:27:45 -03:00
|
|
|
|
2025-03-02 00:41:20 -03:00
|
|
|
|
2025-03-01 01:12:00 -03:00
|
|
|
p { class = "description", blog.description }
|
2025-02-26 14:39:07 -03:00
|
|
|
},
|
|
|
|
|
2025-02-27 13:10:42 -03:00
|
|
|
-- render the pinned post list
|
|
|
|
section(function(o)
|
|
|
|
if #pinned_posts == 0 then
|
|
|
|
o.style = "display: none;"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
o.class = "post-list pinned-posts"
|
|
|
|
table.insert(o, h2 { phosphor("push-pin"), " Pinned:" })
|
|
|
|
|
|
|
|
for _, post in ipairs(pinned_posts) do
|
|
|
|
table.insert(o, render_post(post))
|
|
|
|
end
|
|
|
|
end),
|
|
|
|
|
|
|
|
-- render the post list
|
|
|
|
section(function(o)
|
|
|
|
if #posts == 0 then
|
|
|
|
table.insert(o,
|
|
|
|
p {
|
|
|
|
class = "centered",
|
|
|
|
"Nothing here yet!"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
o.class = "post-list"
|
|
|
|
table.insert(o, h2 { phosphor("note"), " Posts:" })
|
|
|
|
|
|
|
|
-- for each post
|
|
|
|
for _, post in ipairs(blog.index) do
|
|
|
|
table.insert(o, render_post(post)) -- render that boy
|
|
|
|
end
|
|
|
|
end)
|
2025-02-26 14:39:07 -03:00
|
|
|
}
|
|
|
|
end
|