olexsmir.xyz/lua/blog/init.lua(view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
local css = require "lego.css"
local file = require "lego.file"
local html = require "lego.html"
local liblego = require "liblego"
local post = require "lego.post"
local rss = require "lego.rss"
local sitemap = require "lego.sitemap"
local c = require "blog.config"
local pages = require "blog.pages"
local styles = require "blog.styles"
local blog = {}
local function write(fpath, data)
file.write({ c.build.output, fpath }, data)
end
local function write_page(fpath, node)
write(fpath, html.render_page(node))
end
local function write_gopkg(name, repo, branch)
branch = branch or "main"
write(name .. ".html", html.render_page(pages.gopkg(name, repo, branch)))
end
function blog.build()
--- clean up
if file.is_dir(c.build.output) then
file.rm(c.build.output)
end
file.mkdir(c.build.output)
file.copy_dir(c.build.static, c.build.output)
-- write the pages
---@type lego.Post[]
local posts = vim
.iter(file.list_dir(c.build.posts))
:map(function(fname)
return post.read_file { c.build.posts, fname }
end)
:totable()
post.sort_by_date(posts)
write("CNAME", c.cname)
write("chroma.css", liblego.get_css(c.build.chroma_theme))
write("sitemap.xml", sitemap.sitemap(posts, { site_url = c.url }))
write("style.css", css.style(styles))
write(".nojekyll", "")
write_page("404.html", pages.not_found())
write_page("index.html", pages.home(posts))
write_page("posts.html", pages.posts(posts))
write_gopkg("json2go", "https://github.com/olexsmir/json2go")
write_gopkg("moviefeed", "https://github.com/olexsmir/moviefeed")
write_gopkg("mugit", "https://git.olexsmir.xyz/mugit")
write_gopkg("smutok", "https://github.com/olexsmir/smutok")
write_gopkg("x", "https://github.com/olexsmir/x")
-- stylua: ignore
write("feed.xml", rss.rss(posts, {
email = c.email,
name = c.name,
title = c.title,
subtitle = c.feed.subtitle;
feed_url = c.feed.url,
home_url = c.url,
}))
for _, p in pairs(posts) do
local phtml = html.render_page(pages.post(p))
write(p.meta.slug .. ".html", phtml)
end
file.report_duplicates()
end
return blog
|