diff options
author | the lemons <citrons@mondecitronne.com> | 2022-02-06 22:56:03 -0600 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2022-02-06 22:56:03 -0600 |
commit | 770d7d596da31fe8bcec6267ef3fbca8ea934483 (patch) | |
tree | 0bdb2463a311bf129d7bd79893e40c8e2f7d3d74 | |
parent | 4b5f42535bb5fde5b346497e70960a2769839502 (diff) |
ui for illustration
-rwxr-xr-x | zzcxz.cgi | 56 |
1 files changed, 55 insertions, 1 deletions
@@ -119,7 +119,7 @@ local base = template [[ <h1>zzcxz</h1> <main>$content</main> <footer> - <div id="about-links"> + <div class="links"> <p><a href="/">back to start</a></p> <p><a href="/about">help</a></p> <p><a href="https://citrons.xyz/git/zzcxz.git/about"> @@ -221,6 +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 else local target, action = line:match "^(%w%w%w%w%w):(.-)\n$" if action then @@ -292,11 +294,16 @@ local map = {} local page_template = template [[ <h2>$title</h2> + $illustration $content + $drawthis <ul class="actions"> $actions </ul> ]] +local draw_this = [[ + <p id="draw-this"><a href="$page/illustrate">illustrate this</a></p> +]] map["^/g/(%w%w%w%w%w)$"] = function(p) local page = load_page(p) if not page then return not_found() end @@ -318,12 +325,28 @@ map["^/g/(%w%w%w%w%w)$"] = function(p) ) end + local illustration, draw_this + if page.illustrated then + illustration = ([[ + <img class="illustration" src="/i/%s.png" /> + ]]):format(p) + else + draw_this = ([[ + <p id="draw-this"><a href="%s/illustrate"> + illustrate this + </a></p> + ]]):format(p) + end + return base { title = html_encode(page.title), content = page_template { title = html_encode(page.title), content = convert_markup(page.content), actions = table.concat(actions), + page = p, + illustration = illustration, + drawthis = draw_this, }, } else @@ -426,6 +449,37 @@ map["^/g/(%w%w%w%w%w)/act$"] = function(p) end end +local illustrate_template = template [[ + <h2>$title</h2> + $content + <hr/> + <h2 id="what">what does this look like?</h2> + <form action="/g/$page" enctype="multipart/form-data" id="img-form"> + <input + type="file" + name="file" + accept="image/png,image/jpeg,image/gif" + /> + <input type="submit" value="submit image" /> + </form> +]] +map["^/g/(%w%w%w%w%w)/illustrate"] = function(p) + local page = load_page(p) + if not page then return not_found() end + + if env "REQUEST_METHOD" ~= "POST" then + return base { + title = "illustration: " .. html_encode(page.title), + content = illustrate_template { + title = html_encode(page.title), + content = convert_markup(page.content), + page = p, + }, + } + else + end +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 |