1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
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 .. 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('label',{['for']='horse'},'please type the word "horse"'),
tag('input',{id='horse',name='horse',type='text'},''),
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
}))
|