diff options
author | ubq323 <ubq323@ubq323.website> | 2022-11-30 21:30:30 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2022-11-30 21:30:30 +0000 |
commit | acea95639d00d9ddf2e5d87fc93fc61698350e1c (patch) | |
tree | 4e8aa9fcf8a6a213af11f5a7214a5064f9e05713 | |
parent | fb729031a5de0123b593f337c3c5e20c92e45550 (diff) |
refactor of head
-rw-r--r-- | h.lua | 43 | ||||
-rw-r--r-- | index.lua | 9 |
2 files changed, 38 insertions, 14 deletions
@@ -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</%s>"):format(tag.tname,attrs,maybenl,html(tag.body),tag.tname) end - return ("<%s%s>"..bf.."</%s>"):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 @@ -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 }) |