From d2fab210ca437643e420b9924650f1551e497f8b Mon Sep 17 00:00:00 2001 From: the lemons Date: Sun, 6 Feb 2022 23:24:17 -0600 Subject: implement displaying images --- static/amethyst.css | 25 ++++++++++++++++++++++--- zzcxz.cgi | 39 +++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/static/amethyst.css b/static/amethyst.css index 904a2bc..cba224f 100644 --- a/static/amethyst.css +++ b/static/amethyst.css @@ -65,13 +65,13 @@ footer { font-style: italic; } -#about-links { +.links { display: flex; justify-content: flex-end; flex-wrap: wrap; } -#about-links > p { +.links > p { margin-left: 20px; white-space: nowrap; } @@ -123,6 +123,12 @@ button, input[type="submit"] { min-width: 100px; } +input[type="file"] { + font-size: inherit; + font-style: italic; + cursor: pointer; +} + button:active, input[type="submit"]:active { background-color: lightblue; } @@ -248,7 +254,6 @@ grge { font-size: smaller; } - .important { color: cyan !important; } @@ -258,6 +263,20 @@ grge { box-sizing: border-box; } +#draw-this { + font-size: small; +} + +#img-form { + display: flex; + align-items: center; + flex-wrap: wrap; +} + +.illustration { + border-radius: 20px; +} + pre { background-color: white; padding: 10px; diff --git a/zzcxz.cgi b/zzcxz.cgi index 2b8103b..606a76c 100755 --- a/zzcxz.cgi +++ b/zzcxz.cgi @@ -221,8 +221,8 @@ local function parse_page(s) for line in (s..'\n'):gmatch "(.-\n)" do if line:sub(1,1) == '\t' then table.insert(content, line:sub(2)) - elseif line == "!image" then - page.illustrated = true + elseif line:match("^!image") then + page.illustration = line:match "^!image%s+(%w+)" else local target, action = line:match "^(%w%w%w%w%w):(.-)\n$" if action then @@ -326,10 +326,10 @@ map["^/g/(%w%w%w%w%w)$"] = function(p) end local illustration, draw_this - if page.illustrated then + if page.illustration then illustration = ([[ - - ]]):format(p) + + ]]):format(p, page.illustration) else draw_this = ([[

@@ -480,6 +480,17 @@ map["^/g/(%w%w%w%w%w)/illustrate"] = function(p) end end +map["^/i/(%w%w%w%w%w).(%w+)$"] = function(p, format) + local page = load_page(p) + if not page or + not page.illustration or not page.illustration == format then + return not_found() + end + return + assert(io.open(('content/%s.%s'):format(p, format), 'r')), + { content_type = 'image/'..format } +end + map["^/g/(%w%w%w%w%w)/raw$"] = function(p) local page = load_page(p, true) if not page then return not_found() end @@ -488,11 +499,7 @@ map["^/g/(%w%w%w%w%w)/raw$"] = function(p) end map["^/about/?$"] = function() - local f = assert(io.open("about.html", 'r')) - local h = assert(f:read 'a') - f:close() - - return h + return assert(io.open("about.html", 'r')) end local function main() @@ -510,7 +517,7 @@ local function main() end local ok, content, resp = pcall(main) -if not ok or type(content) ~= 'string' then +if not ok or (type(content) ~= 'string' and type(content) ~= 'userdata') then io.stderr:write(content..'\n') content = base { @@ -532,4 +539,12 @@ for k,v in pairs(resp.headers) do end print "" -io.write(content) +if type(content) == 'string' then + io.write(content) +else + while 1 do + local data = content:read(1024) + if not data then break end + io.write(data) + end +end -- cgit v1.2.3