From acea95639d00d9ddf2e5d87fc93fc61698350e1c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 30 Nov 2022 21:30:30 +0000 Subject: refactor of head --- h.lua | 43 ++++++++++++++++++++++++++++++++++++------- index.lua | 9 ++------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/h.lua b/h.lua index b36c855..5c62e66 100644 --- a/h.lua +++ b/h.lua @@ -27,14 +27,15 @@ local function fmt_attrs(attrs) end local function fmt_tag(tag) - local a = tag.attrs and fmt_attrs(tag.attrs) or "" - local bf - if type(tag.body) == "string" or (type(tag.body) == "table" and tag.body.tag) then - bf = "%s" + local attrs = tag.attrs and fmt_attrs(tag.attrs) or "" + local selfclosing = (tag.body == "") + local sameline = type(tag.body) == "string" or (type(tag.body) == "table" and tag.body.tag) + local maybenl = sameline and "" or "\n" + if selfclosing then + return ("<%s%s/>"):format(tag.tname,attrs) else - bf = "\n%s" + return ("<%s%s>%s%s"):format(tag.tname,attrs,maybenl,html(tag.body),tag.tname) end - return ("<%s%s>"..bf..""):format(tag.tname,a,html(tag.body),tag.tname) end function tag(tname, a1, a2) @@ -87,7 +88,7 @@ function qw(s) for a in s:gmatch("%w+") do table.insert(t,a) end return t end -local tnames = qw"h1 h2 p b ul li dl dt dd div section header figure figcaption" +local tnames = qw"h1 h2 p b ul li dl dt dd div section header figure figcaption img title" for _,n in ipairs(tnames) do _G[n] = tagfn(n) end @@ -100,3 +101,31 @@ function readf(fname) return c end function safereadf(fname) return safe(readf(fname)) end + +function mkhead(t) + -- includes css and stuff, and title element + return { + safereadf "head.html", + title(t), + } +end + +-- the box at the top with the cool picture of me in, etc +-- presumably the same on all pages +site_top = header { + img({id="me",src="/me.png"},""), + h1 "ubq323's website", + p [[rebecca, "ubq323" (she/her, 20) - eminently engromulent]], +} + + +function blogpost(meta, content) + -- creates a whole page + + return { + mkhead(meta.title), + site_top, + section(content), + -- maybe footer? + } +end diff --git a/index.lua b/index.lua index fea3fec..d8f7c2e 100644 --- a/index.lua +++ b/index.lua @@ -1,11 +1,6 @@ require"h" -head ={ safereadf "head.html", tag("title","ubq323's website") } -top = header { - tag("img",{id="me",src="me.png"},""), - h1 "ubq323's website", - p [[rebecca, "ubq323" (she/her, 20) - eminently engromulent]], -} +head = mkhead("ubq323's website") function l(text,path) return li(a(text,path or "/"..text)) end mainsect = section { @@ -47,5 +42,5 @@ footer = safe [[ print(html{ - head, top, mainsect, contact, footer + head, site_top, mainsect, contact, footer }) -- cgit v1.2.3