diff options
Diffstat (limited to 'questions/questions.lua')
-rw-r--r-- | questions/questions.lua | 69 |
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 +})) + + + |