aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-02-05 16:56:08 -0600
committerthe lemons <citrons@mondecitronne.com>2022-02-05 16:56:08 -0600
commit99db12fcecadb7afc2913abddf54f4bcc5fbb793 (patch)
tree4380ab16ed14035bef896a8924378ce5fa908839
parent89225c344bf4e631c459f39c6664f8b870abfc84 (diff)
add #REDIRECT
-rw-r--r--about.html5
-rw-r--r--static/amethyst.css5
-rwxr-xr-xzzcxz.cgi27
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
@@ -66,13 +66,16 @@
type <code>#BACKLINK &lt;room&gt; &lt;action&gt;</code> on its own line to cause the room to link back to an already existing room. replace <code>&lt;action&gt;</code> with the text you desire to appear in the link. replace <code>&lt;room&gt;</code> with everything after <code>https://zzcxz.citrons.xyz/g/</code>. for example, to make a link with the text "go back" which links to <code>https://zzcxz.citrons.xyz/g/xxxxx</code>, type the line <code>#BACKLINK xxxxx go back</code>. <code>#BACKLINK</code> cannot add new actions.
<li>
+ type <code>#REDIRECT &lt;room&gt;</code> to cause the action to bring you to <code>&lt;room&gt;</code> instead of a new room. like with <code>#BACKLINK</code> replace <code>&lt;room&gt;</code> with the five letters at the end of the url of the desired room.
+
+ <li>
type <code>#DEADEND</code> to prevent people from taking additional actions on the page. this is mostly useful in combination with <code>#BACKLINK</code>.
<li>
you can add <code>/raw</code> to the end of the URL of a room to see its markup (on the lines starting with tab) (<a href="/g/zzcxz/raw">example</a>). this feature could also potentially be utilized to implement third-party interfaces.
</ul>
-
+
<p>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.</p>
<h2 id="where can I discuss">where can I discuss zzcxz?</h2>
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></pre>')
code_block = false
end
+
+ if directives.redirect then
+ local r = directives.redirect
+ return
+ ('<p class="note">this action will link to <a href=%s>%s</a></p>')
+ :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)))