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

33 lines
831 B
Scheme

(define-structure plugin plugin-interface
(open scsh
scheme
servlets
crlf-io)
(begin
(define *data* '())
(define (read-data)
(let ((news-input (open-input-file "news.txt")))
(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-html/finish
`(html (body (p (h1 "THAT'S IT"))
(p ("That's it...")))))
(begin
(send-html/suspend
(lambda (next-url)
`(html (body (p (h1 ,(list-ref *data* count))))
(a (@ href ,next-url) "read more..."))))
(loop (- count 1))))))
))