sunet/web-server/root/surflets/news.scm

54 lines
1.2 KiB
Scheme
Raw Normal View History

2002-09-13 03:21:19 -04:00
(define-structure plugin plugin-interface
(open scsh
scheme
plugin-utilities
httpd-responses
crlf-io)
(begin
2002-09-14 11:18:12 -04:00
(define *data* '())
(define (read-data)
2002-09-13 03:21:19 -04:00
(let ((news-input (open-input-file "news.txt")))
2002-09-14 11:18:12 -04:00
(let loop ((next-line (read-crlf-line news-input)))
(if (eof-object? next-line)
(close news-input)
(begin
(set! *data* (cons next-line *data*))
(loop (read-crlf-line news-input)))))))
(define (main req)
(if (null? *data*) (read-data))
(let loop ((count (- (length *data*) 1)))
(if (< count 0)
(send/finish
(make-response
http-status/ok
(status-code->text http-status/ok)
(time)
"text/html"
'()
(make-writer-body
(lambda (out options)
(format out
"<HTML><BODY><H1>THAT'S IT<H1><P>
That's it...</BODY></HTML>")))))
(begin
(send/suspend
(lambda (next-url)
2002-09-13 03:21:19 -04:00
(make-response
http-status/ok
(status-code->text http-status/ok)
(time)
"text/html"
'()
(make-writer-body
(lambda (out options)
(format out
2002-09-14 11:18:12 -04:00
"<HTML><BODY><H1>~a<H1><P>
2002-09-13 03:21:19 -04:00
<A href=~a>read more...</A></BODY></HTML>"
2002-09-14 11:18:12 -04:00
(list-ref *data* count)
next-url))))))
(loop (- count 1))))))
2002-09-13 03:21:19 -04:00
))
2002-09-14 11:18:12 -04:00