-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.cgi
executable file
·76 lines (68 loc) · 2.37 KB
/
archive.cgi
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
72
73
74
75
76
#!/usr/bin/env gosh
; -*- scheme -*-
(use sxml.serializer)
(use www.cgi)
(use file.util)
(use util.list)
(load "./file")
(define (main args)
(frontend read-from-log-no-wait archive-filter))
(define (frontend reader filter)
(cgi-main
(lambda (params)
(let ((log-file (cgi-get-parameter "q" params)))
`(,(cgi-header :content-type "text/html;charset=utf-8")
,(srl:sxml->xml-noindent
(if log-file
(receive (exps file pos) (reader log-file 0)
`(*TOP* (html (head (title "log " ,file))
(script "function init (x) {if (n = location.href.match(/#(.+)$/)) {document.getElementById('e'+n[1]).style.backgroundColor='#ffcccc'}}")
(body
(@ (onload "init()"))
(ul ,@(filter exps))))))
`(*TOP* (html (head (title "log archive"))
(body (ul
,@(map (lambda (f) `(li (a (@ (href ,#`"./archive.cgi?q=,f")) ,f))) (log-files))))))
)))))))
(define (archive-filter exps)
(map (lambda (x)
(guard (e (else (ref e 'message)))
(eval x (interaction-environment))))
exps))
;;;;;;;;;;;;;
; (chat-entry
; (link (file "data/data.1234567890.1234.log") (pos 123))
; (date (posix-time 1253048216))
; (from (user-by-nickname (string "とおる。"))
; (avatar-image (string "http://www.gravatar.com/avatar/5efc507a8db7167e2db7889a5597a3cd?s=40&default=identicon")))
; (content (string "あれ、名前がない。")))
(define (chat-entry . params)
(let ((data (fold (lambda (x p)
(if x (cons x p) p))
() params)))
`(li (@ (id ,(string-append "e" (cdr (assoc 'pos data)))))
(a (@ (name ,(cdr (assoc 'pos data))))
,(cdr (assoc 'name data)))
(span (@ (style "padding-left: 10ex;font-size: small"))
(a (@ (href ,(string-append "#" (cdr (assoc 'pos data))))) ,(cdr (assoc 'date data))))
(br)
,@(cdr (assoc 'content data)))
))
(define (link file p) (cons 'pos p))
(define (file x) x)
(define (pos p) (x->string p))
(define (date x) (cons 'date (sys-ctime x)))
(define (posix-time x) (x->number x))
(define (from . params)
(let loop ((params params))
(if (car params)
(cons 'name (car params))
(loop (cdr params)))))
(define (user-by-nickname x) x)
(define (string x) x)
(define (avatar-image x) #f)
(define (content x) (cons 'content (intersperse '(br) (string-split x #\newline))))
(define (system x) #f)
(define (new-file x) #f)
(define (room x) #f)
(define (|@| x) #f)