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

45 lines
1.1 KiB
Scheme
Raw Normal View History

2003-01-19 11:57:27 -05:00
(define-structure surflet surflet-interface
(open scheme-with-scsh
2003-01-19 11:57:27 -05:00
surflets)
2002-09-13 03:21:19 -04:00
(begin
2003-01-19 06:03:14 -05:00
(define *news* '())
2002-09-14 11:18:12 -04:00
2003-01-19 06:03:14 -05:00
(define (read-news news-file-name)
(close-after (open-input-file news-file-name)
(lambda (news-input)
(let loop ((next-line (read-line news-input))
(news '()))
(if (eof-object? next-line)
news
(loop (read-line news-input)
(cons next-line news)))))))
2002-09-14 11:18:12 -04:00
(define (main req)
2003-01-19 06:03:14 -05:00
(if (null? *news*)
(set! *news* (read-news "news.txt")))
(let loop ((news *news*))
(if (null? news)
2003-01-19 04:47:15 -05:00
(show-final-page)
2002-09-14 11:18:12 -04:00
(begin
2003-01-19 06:03:14 -05:00
(show-news-page (car news))
(loop (cdr news))))))
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 04:47:15 -05:00
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