From 99db12fcecadb7afc2913abddf54f4bcc5fbb793 Mon Sep 17 00:00:00 2001 From: the lemons Date: Sat, 5 Feb 2022 16:56:08 -0600 Subject: add #REDIRECT --- about.html | 5 ++++- static/amethyst.css | 5 +++++ zzcxz.cgi | 27 ++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/about.html b/about.html index 802194a..a96a417 100644 --- a/about.html +++ b/about.html @@ -65,6 +65,9 @@
  • type #BACKLINK <room> <action> on its own line to cause the room to link back to an already existing room. replace <action> with the text you desire to appear in the link. replace <room> with everything after https://zzcxz.citrons.xyz/g/. for example, to make a link with the text "go back" which links to https://zzcxz.citrons.xyz/g/xxxxx, type the line #BACKLINK xxxxx go back. #BACKLINK cannot add new actions. +
  • + type #REDIRECT <room> to cause the action to bring you to <room> instead of a new room. like with #BACKLINK replace <room> with the five letters at the end of the url of the desired room. +
  • type #DEADEND to prevent people from taking additional actions on the page. this is mostly useful in combination with #BACKLINK. @@ -72,7 +75,7 @@ you can add /raw to the end of the URL of a room to see its markup (on the lines starting with tab) (example). this feature could also potentially be utilized to implement third-party interfaces. - +

    if you use special formatting, and you see the literal characters that you intend to use to invoke special formatting, you have an error in your formatting. for instance, you should never see "#BACKLINK" in the preview.

    where can I discuss zzcxz?

    diff --git a/static/amethyst.css b/static/amethyst.css index 3312a69..2d08dd4 100644 --- a/static/amethyst.css +++ b/static/amethyst.css @@ -74,6 +74,11 @@ footer { margin-left: 20px; } +.note { + color: lightgrey; + font-style: italic; +} + hr { border-bottom: 0; border-left: 0; diff --git a/zzcxz.cgi b/zzcxz.cgi index 0c4b290..696c7b0 100755 --- a/zzcxz.cgi +++ b/zzcxz.cgi @@ -151,12 +151,17 @@ local function parse_directive(line, directives) table.insert(directives.backlinks, {page = page, action = action}) elseif directive == "deadend" then directives.deadend = true + elseif directive == "redirect" then + local redirect = args:match "^%s*(%w%w%w%w%w)%s*$" + if not redirect then return end + directives.redirect = redirect else return end return true end +local load_page local function convert_markup(m) local result = {} local directives = {} @@ -197,6 +202,15 @@ local function convert_markup(m) table.insert(result, '') code_block = false end + + if directives.redirect then + local r = directives.redirect + return + ('

    this action will link to %s

    ') + :format(r, r), + directives + end + return table.concat(result), directives end @@ -220,7 +234,7 @@ local function parse_page(s) return page end -local function load_page(p, raw) +function load_page(p, raw) if not p:match("^%w%w%w%w%w$") then return nil end local f, bee = io.open('content/'..p) if not f then return nil end @@ -232,6 +246,15 @@ local function load_page(p, raw) end local function new_action(page, action, result) + local _, directives = convert_markup(result) + local old = assert(io.open('content/'..page, 'a')) + + if directives.redirect then + assert(old:write(('%s:%s\n'):format(directives.redirect, action))) + old:close() + return directives.redirect + end + local new_name = {} for i=1,5 do table.insert(new_name, string.char(string.byte 'a' + math.random(0,25))) @@ -240,7 +263,6 @@ local function new_action(page, action, result) assert(not io.open('content/'..new_name, 'r'), "page already exists!") local new = assert(io.open('content/'..new_name, 'w')) - local old = assert(io.open('content/'..page, 'a')) action = action:gsub('\n', ' ') assert(new:write(action..'\n')) @@ -249,7 +271,6 @@ local function new_action(page, action, result) end assert(old:write(('%s:%s\n'):format(new_name, action))) - local _, directives = convert_markup(result) if directives.backlinks then for _,d in ipairs(directives.backlinks) do assert(new:write(('%s:%s\n'):format(d.page, d.action))) -- cgit v1.2.3