From 8686fd9baead75969139b43a42dd8ef298b9fd68 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Mon, 30 Jun 2025 15:20:40 +0200 Subject: [PATCH] Style refactor and per-post images --- .luarc.json | 3 ++ blog-dev-1.rockspec | 2 +- build.lua | 51 ++++++++++++++----- lib/paramparser.lua | 1 - lib/posts.lua | 10 ++-- lib/tags.lua | 1 - pages/index.html.skooma.yue | 6 +-- {css => static/css}/site.css | 3 ++ {javascript => static/javascript}/BlogPost.js | 0 .../javascript}/LocalDate.js | 0 tasks.lua | 2 +- templates/main.html.skooma.yue | 12 ++--- templates/post.html.skooma.yue | 2 +- 13 files changed, 62 insertions(+), 31 deletions(-) create mode 100644 .luarc.json rename {css => static/css}/site.css (84%) rename {javascript => static/javascript}/BlogPost.js (100%) rename {javascript => static/javascript}/LocalDate.js (100%) diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..23b9ee2 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,3 @@ +{ + "workspace.checkThirdParty": false +} \ No newline at end of file diff --git a/blog-dev-1.rockspec b/blog-dev-1.rockspec index 2d4f290..947ed07 100644 --- a/blog-dev-1.rockspec +++ b/blog-dev-1.rockspec @@ -15,7 +15,7 @@ dependencies = { "lua-cjson ~> 2.1", "restia", "rgbstr", - "scaffold ~> 1.1", + "scaffold ~> 1.3.1", "shapeshift ~> 1.1", "skooma", "streamcsv ~> 1.1", diff --git a/build.lua b/build.lua index 0d97102..b93507c 100644 --- a/build.lua +++ b/build.lua @@ -10,15 +10,22 @@ local atom = require 'feed.atom' local paramparser = require 'paramparser' local params = paramparser(...) package.loaded.params = params -local config = require 'config' local pages = require 'pages' local templates = require 'templates' local posts = require 'posts' -local tree = {} +local output_tree = {} -for i, path in ipairs(params.copy) do - scaffold.deep(tree, path, scaffold.readdir(path)) +for name, content in pairs(scaffold.readdir("static")) do + scaffold.deep(output_tree, name, content) +end + +local function is_image(name) + if name:downcase():match("^.jpg$") then + return true + else + return false + end end local function render(name, data) @@ -30,19 +37,39 @@ local function page(name, data) end -- Render Posts -for idx, post in ipairs(posts) do +for _, post in ipairs(posts) do local body = tostring(render("post", post)) - scaffold.deep(tree, post.path, body) + scaffold.deep(output_tree, post.path, body) end -scaffold.deep(tree, "feeds/all.rss.xml", rss(posts)) -scaffold.deep(tree, "feeds/all.atom.xml", atom(posts)) +scaffold.deep(output_tree, "feeds/all.rss.xml", rss(posts)) +scaffold.deep(output_tree, "feeds/all.atom.xml", atom(posts)) if params.delete then restia.utils.delete(params.output) end +do -- Copy blog images + local function iter_files(tree, callback) + if getmetatable(tree) == scaffold.lazy then + callback(tree) + else + for _, node in pairs(tree) do + iter_files(node, callback) + end + end + end + + iter_files(scaffold.readdir("posts", {files = "lazy"}), function(file) + local name = file.path:match("[^/]+$") + if name:find(".jpg$") then + local path = "/images/" .. name + scaffold.deep(output_tree, path, file) + end + end) +end + local function transform(tab) return function(data) local success, result = shapeshift.table(tab, "keep")(data) @@ -53,7 +80,7 @@ end local function drop() return true, nil end -- Generate Post Metadata -tree["posts.json"] = json.encode( +output_tree["posts.json"] = json.encode( fun .iter(posts) :map(transform { @@ -63,10 +90,10 @@ tree["posts.json"] = json.encode( :totable() ) -tree["index.html"] = tostring(page("index", tree["posts.json"])) +output_tree["index.html"] = tostring(page("index", output_tree["posts.json"])) if params.cname then - tree.CNAME = params.cname + output_tree.CNAME = params.cname end -scaffold.builddir(params.output, tree) +scaffold.builddir(params.output, output_tree) diff --git a/lib/paramparser.lua b/lib/paramparser.lua index 456e556..325c1c0 100644 --- a/lib/paramparser.lua +++ b/lib/paramparser.lua @@ -6,7 +6,6 @@ return function(...) local parse = arrr { { "Output directory", "--output", "-o", 'directory' }; { "Input directory", "--input", "-i", 'directory' }; - { "Copy directory", "--copy", "-c", 'directory', 'repeatable' }; { "Include unpublished posts", "--unpublished", "-u", nil }; { "Set the github pages CNAME", "--cname", nil, 'domain' }; { "Delete everything first", "--delete", "-d" }; diff --git a/lib/posts.lua b/lib/posts.lua index 6b33b97..d5dd59c 100644 --- a/lib/posts.lua +++ b/lib/posts.lua @@ -7,11 +7,11 @@ local string = require 'stringplus' local function parsedate(date) local year, month, day = date:match("(%d+)%-(%d+)%-(%d+)") - return os.time { - year = tonumber(year); - month = tonumber(month); - day = tonumber(day); - } + return os.time { + year = tonumber(year) or error("Invalid date string: " .. date); + month = tonumber(month) or error("Invalid date string: " .. date); + day = tonumber(day) or error("Invalid date string: " .. date); + } end local validate_head do diff --git a/lib/tags.lua b/lib/tags.lua index 5941ada..bdaa735 100644 --- a/lib/tags.lua +++ b/lib/tags.lua @@ -19,7 +19,6 @@ return function(tags) end return { html.flexRow(list); - html.verticalSpacer(); } end end diff --git a/pages/index.html.skooma.yue b/pages/index.html.skooma.yue index 1dc26e5..cbb9167 100644 --- a/pages/index.html.skooma.yue +++ b/pages/index.html.skooma.yue @@ -7,9 +7,9 @@ post = => color = table.concat({rgbstr.bytes(@head.tags[1], 16, .3, .5)}, " ") flexColumn class: "info box", style: "--color: rgb(#{color})" * h2 a(@head.title, href: @head.uri), style: "view-transition-name: #{@head.slug}" + * small time is: 'local-date', datetime: @head.date, @head.date + * p @head.description * tags(@head.tags) - * time is: 'local-date', datetime: @head.date, @head.date - * @head.description slots.head title "Talia's Blog" @@ -23,7 +23,7 @@ slots.head slots.head script type: 'module', src: "/javascript/LocalDate.js" slots.head script type: 'module', src: "/javascript/BlogPost.js" -return main +return article class: "content-width" * h1 "Blog Posts" * [blogPost post p for p in *posts] diff --git a/css/site.css b/static/css/site.css similarity index 84% rename from css/site.css rename to static/css/site.css index ebcf126..7223252 100644 --- a/css/site.css +++ b/static/css/site.css @@ -1,3 +1,6 @@ +@import url('https://cdn.jsdelivr.net/gh/darkwiiplayer/css@main/all.css') layer(framework); +@import url('https://cdn.jsdelivr.net/gh/darkwiiplayer/css@main/drop-in.css') layer(framework); + blog-post[hidden] { display: none; } diff --git a/javascript/BlogPost.js b/static/javascript/BlogPost.js similarity index 100% rename from javascript/BlogPost.js rename to static/javascript/BlogPost.js diff --git a/javascript/LocalDate.js b/static/javascript/LocalDate.js similarity index 100% rename from javascript/LocalDate.js rename to static/javascript/LocalDate.js diff --git a/tasks.lua b/tasks.lua index 6059fdf..3b5cbd0 100644 --- a/tasks.lua +++ b/tasks.lua @@ -25,7 +25,7 @@ task.build { [[ export LUA_PATH='%s' export LUA_CPATH='%s' - lua build.lua --copy css --copy javascript --output blog --cname blog.but.gay + lua build.lua --output blog --cname blog.but.gay ]], path, cpath ) diff --git a/templates/main.html.skooma.yue b/templates/main.html.skooma.yue index 2699c10..175e8f8 100644 --- a/templates/main.html.skooma.yue +++ b/templates/main.html.skooma.yue @@ -2,19 +2,21 @@ import output from require 'params' import slotty from require 'skooma' import 'config' +slots = slotty! + styles = [[ @import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Fira+Code&display=swap'); + @view-transition { navigation: auto; } + :root { container: style; } :is(h1, h2, h3, h4, h5, h6) { font-family: "Raleway", sans-serif; } :is(code, kbd, var, samp) { font-family: "Fira Code", monospace; } .badge { font-family: "Open Sans", sans-serif } ]] -slots = slotty! - slots.footer aside id: "contact" * h2 "Social" * p @@ -26,7 +28,7 @@ slots.footer aside id: "git" * h2 "Git" * ul * li a "Github", href: "https://github.com/darkwiiplayer" - * li a "Gitea", href: "https://git.but.gay/darkwiiplayer" + * li a "Forgejo", href: "https://git.but.gay/darkwiiplayer" slots.footer aside id: "platforms" * h2 "Federated cloud" @@ -44,8 +46,6 @@ html * meta name: "view-transition", content: "same-origin" * meta charset: "UTF-8" * meta name: "viewport", content: "width=device-width" - * css 'https://darkwiiplayer.github.io/css/all.css' - * css 'https://darkwiiplayer.github.io/css/schemes/talia.css' * css "/css/site.css" * style styles * slots.head @@ -54,7 +54,7 @@ html * slots.top * header class: 'sticky', style: "view-transition-name: header" * h1 "Talia's Blog" - * nav { class: 'right bar' } + * nav { class: 'right underlined bar' } * ul li a "Home", href: "/" * main * content slots, data diff --git a/templates/post.html.skooma.yue b/templates/post.html.skooma.yue index 572fd17..8720281 100644 --- a/templates/post.html.skooma.yue +++ b/templates/post.html.skooma.yue @@ -41,7 +41,7 @@ else slots.summary div post.head.description, class: "summary", tabindex: 0 slots.summary verticalSpacer -slots.banner aside class: { 'box' } +slots.banner aside class: { 'floating box' }, stripe: "rebeccapurple" * b "Hey there!" * p raw [[ This blog doesn't use any tracking. When you open this page, I don't see