1
+ #lang web-server/insta
2
+
3
+ ; A blog is a (listof post)
4
+ ; and a post is a (post title body)
5
+ (struct post (title body))
6
+
7
+ ; BLOG: blog
8
+ ; The static blog.
9
+ (define BLOG
10
+ (list (post "Second Post " "This is another post " )
11
+ (post "First Post " "This is my first post " )))
12
+
13
+ ; start: request -> response
14
+ ; Consumes a request, and produces a page that displays all of the
15
+ ; web content.
16
+ (define (start request)
17
+ (render-blog-page BLOG request))
18
+
19
+ ; render-blog-page: blog request -> response
20
+ ; Consumes a blog and a request, and produces an HTML page
21
+ ; of the content of the blog.
22
+ (define (render-blog-page a-blog request)
23
+ (response/xexpr
24
+ `(html (head (title "My Blog " ))
25
+ (body (h1 "My Blog " )
26
+ ,(render-posts a-blog)))))
27
+
28
+ ; render-post: post -> xexpr
29
+ ; Consumes a post, produces an xexpr fragment of the post.
30
+ (define (render-post a-post)
31
+ `(div ((class "post " ))
32
+ ,(post-title a-post)
33
+ (p ,(post-body a-post))))
34
+
35
+ ; render-posts: blog -> xexpr
36
+ ; Consumes a blog, produces an xexpr fragment
37
+ ; of all its posts.
38
+ (define (render-posts a-blog)
39
+ `(div ((class "posts " ))
40
+ ,@(map render-post a-blog)))
0 commit comments