From 7a89e7148c5a9995c3b772440ed0b86427c8b708 Mon Sep 17 00:00:00 2001 From: the lemons Date: Tue, 8 Feb 2022 02:20:04 -0600 Subject: the log now exists it shows you where you've been/what you've done. when performing a new action, it shows the IDs so that you can redirect to them. --- static/amethyst.css | 24 +++++++++++++++++++ zzcxz.cgi | 67 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/static/amethyst.css b/static/amethyst.css index d80545e..8c618fe 100644 --- a/static/amethyst.css +++ b/static/amethyst.css @@ -273,6 +273,30 @@ grge { flex-wrap: wrap; } +.hist-log > ul { + padding: 10px; + border-radius: 10px; + font-family: monospace; + overflow-y: scroll; + overflow-x: hidden; + height: 190px; + background-color: black; + font-size: larger; +} + +.hist-log > ul > li { + list-style: none; +} + +.hist-log > ul > li:before { + content: "→ "; +} + +.page-id { + color: lightgrey; + font-style: italic; +} + .illustration { border-radius: 20px; } diff --git a/zzcxz.cgi b/zzcxz.cgi index 45a4f1d..f859fa0 100755 --- a/zzcxz.cgi +++ b/zzcxz.cgi @@ -93,6 +93,12 @@ local function parse_qs(str,sep) end local cookies = env "HTTP_COOKIE" and parse_qs(env "HTTP_COOKIE","; ") or {} +local history = {} +if cookies.history then + for page in cookies.history:gmatch "(%w%w%w%w%w)%," do + table.insert(history, page) + end +end local function redirect(to) return "", { @@ -293,14 +299,37 @@ local function new_action(page, action, result) return new_name end -local function get_history() - if not cookies.history then return {} end - - local history = {} - for page in cookies.history:gmatch "(%w%w%w%w%w)%," do - table.insert(history, page) +local hist_template = template [[ +
+ log + +
+]] +local function show_hist(show_ids) + local log = {} + if #history == 0 then return "" end + + for i=#history,1,-1 do + local page = load_page(history[i]) + if not page then goto continue end + + -- highlight the current page + local title = i ~= #history and html_encode(page.title) + or ''..html_encode(page.title)..'' + if show_ids then + table.insert(log, + ('
  • %s %s
  • ') + :format(title, history[i])) + else + table.insert(log, ('
  • %s
  • '):format(title)) + end + ::continue:: end - return history + return hist_template { + log = table.concat(log), + } end local map = {} @@ -313,6 +342,7 @@ local page_template = template [[ + $log ]] local draw_this = [[

    illustrate this

    @@ -323,6 +353,13 @@ map["^/g/(%w%w%w%w%w)$"] = function(p) local _, directives = convert_markup(page.content) if env "REQUEST_METHOD" ~= "POST" then + if history[#history] ~= p then + table.insert(history, p) + end + if #history > 75 then + table.remove(history, 1) + end + local actions = {} for _,a in ipairs(page.actions) do table.insert(actions, @@ -351,15 +388,8 @@ map["^/g/(%w%w%w%w%w)$"] = function(p) -- ]]):format(p) end - local hist = get_history() - if hist[#hist] ~= p then - table.insert(hist, p) - end - if #hist > 25 then - table.remove(hist, 1) - end - local hist_cookie = ('history=%s; path=/; secure; max-age=99999999999') - :format(table.concat(hist, ',')..',') + local hist_cookie = ('history=%s; path=/; max-age=99999999999') + :format(table.concat(history, ',')..',') return base { title = html_encode(page.title), @@ -370,6 +400,7 @@ map["^/g/(%w%w%w%w%w)$"] = function(p) page = p, illustration = illustration, drawthis = draw_this, + log = show_hist(), }, }, { headers = { ['set-cookie'] = hist_cookie } } else @@ -400,7 +431,6 @@ local edit_template = template [[ $content
    $preview - $log

    READ THIS before touching anything. @@ -422,6 +452,7 @@ local edit_template = template [[ $submit + $log

    ]] local preview_template = template [[ @@ -445,6 +476,7 @@ map["^/g/(%w%w%w%w%w)/act$"] = function(p) content = edit_template { page = p, content = convert_markup(page.content), + log = show_hist(true), }, } else @@ -468,6 +500,7 @@ map["^/g/(%w%w%w%w%w)/act$"] = function(p) title = html_encode(form.wyd), editing = html_encode(form.happens), submit = submit_template { page = p }, + log = show_hist(true), }, } end -- cgit v1.2.3