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

43 lines
1.1 KiB
Scheme
Raw Normal View History

2002-10-01 08:33:39 -04:00
(define-structure servlet servlet-interface
(open scheme-with-scsh
servlets)
2002-09-13 03:21:19 -04:00
(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")))
(do ((next-line (read-line news-input)
2003-01-19 05:31:16 -05:00
(read-line news-input))
(data '() (cons next-line data)))
((eof-object? next-line)
(close news-input)
data))))
2002-09-14 11:18:12 -04:00
(define (main req)
2003-01-19 05:31:16 -05:00
(if (null? *data*) (set! *data* (read-data)))
2002-09-14 11:18:12 -04:00
(let loop ((count (- (length *data*) 1)))
(if (< count 0)
2003-01-19 04:47:15 -05:00
(show-final-page)
2002-09-14 11:18:12 -04:00
(begin
2003-01-19 05:31:16 -05:00
(show-news-page (list-ref *data* count))
2002-09-14 11:18:12 -04:00
(loop (- count 1))))))
2003-01-19 04:47:15 -05:00
(define (show-final-page)
(send-html/finish
`(html (body (p (h1 "THAT'S IT"))
(p ("That's it..."))
(hr)
(p (URL "news.scm" "See news again.") (br)
(URL "/" "Return to main menu."))))))
2003-01-19 05:31:16 -05:00
(define (show-news-page news)
2003-01-19 04:47:15 -05:00
(send-html/suspend
(lambda (next-url)
2003-01-19 05:31:16 -05:00
`(html (body (p (h1 ,news))
2003-01-19 04:47:15 -05:00
(a (@ href ,next-url) "read more...")
(hr)
(p (URL "news.scm" "See news again from beginning.") (br)
(URL "/" "Return to main menu.")))))))
2002-09-13 03:21:19 -04:00
))
2002-09-14 11:18:12 -04:00