summaryrefslogtreecommitdiff
path: root/questions/questions.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-05-22 00:24:21 +0100
committerubq323 <ubq323@ubq323.website>2023-05-22 00:30:30 +0100
commit9eb6d483f356a77caf37e819f9666abe3f9a6159 (patch)
tree8bc27abce25a2617e1a54c38dae7f8786a2e005f /questions/questions.lua
parent35409af1e0230323a6bc96de229ef2aa02a2a086 (diff)
questions page
Diffstat (limited to 'questions/questions.lua')
-rw-r--r--questions/questions.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/questions/questions.lua b/questions/questions.lua
new file mode 100644
index 0000000..a0a44ea
--- /dev/null
+++ b/questions/questions.lua
@@ -0,0 +1,69 @@
+require 'h'
+
+function eprint(x)
+ io.stderr:write( tostring(x))
+ io.stderr:write('\n')
+end
+
+
+local fname = arg[0]:gsub('/[^/]-%.lua$','/questions.txt')
+eprint("\treading questions from "..fname)
+local F = io.open(fname,'r')
+
+questions = {}
+
+local lidx = 0
+local line = F:read("l")
+while line do
+ local date, q = line:match("^(.-)\t(.*)$")
+ if not date then break end
+ q = escape(q)
+ local a = "<p>"
+ local aline = F:read("l")
+ while aline and not aline:match("^%-%-%-") do
+ if aline:match("%S") then
+ a = a .. tostring(escape(aline)) .. "\n"
+ else
+ a = a .. '<p>'
+ end
+ aline = F:read("l")
+ end
+ table.insert(questions, 1, {
+ p({class='question-date'},date),
+ h3({class='question-heading'},q),
+ safe(a)
+ })
+ line = F:read("l")
+end
+
+local head = mkhead('questions')
+local top = mksmalltopbox('question and answer')
+local bread = bcrumb{
+ {'< home', '/'},
+ {'q & a'}
+}
+
+local asect = section {
+ h2('submit a question'),
+ tag('form',{action='/misc/submit-question.cgi',method='post'},{
+ tag('textarea',{name='q'},{}),
+ tag('button','submit a question'),
+ })
+}
+
+local qsect
+if #questions > 0 then
+ qsect = section { questions }
+else
+ qsect = section { i'there are no questions yet.' }
+
+end
+
+print(html({
+ head, top, bread,
+ asect,
+ qsect
+}))
+
+
+