host: blog home page GET / -> HTML post index, 179/179
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s
GET / renders an HTML index listing every post (title linking to /<slug>/), built from host/blog-list; empty -> 'No posts yet'. GET /posts stays the JSON API. Live: blog.rose-ash.com/ lists the welcome post linking to /welcome/. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -104,9 +104,24 @@
|
||||
(str "<!doctype html><title>Not found</title>"
|
||||
"<h1>404</h1><p>No published post: " slug "</p>")))))))
|
||||
|
||||
;; GET /posts -> JSON list of posts.
|
||||
;; GET /posts -> JSON list of posts (API).
|
||||
(define host/blog-index (fn (req) (host/ok (host/blog-list))))
|
||||
|
||||
;; GET / -> HTML index page listing posts, each linking to /<slug>/.
|
||||
(define host/blog--li
|
||||
(fn (acc p)
|
||||
(str acc "<li><a href=\"/" (get p :slug) "/\">" (get p :title) "</a></li>")))
|
||||
(define host/blog-home
|
||||
(fn (req)
|
||||
(let ((posts (host/blog-list)))
|
||||
(dream-html
|
||||
(str
|
||||
"<!doctype html><meta charset=\"utf-8\"><title>Blog</title>"
|
||||
"<h1>Posts</h1>"
|
||||
(if (> (len posts) 0)
|
||||
(str "<ul>" (reduce host/blog--li "" posts) "</ul>")
|
||||
"<p>No posts yet.</p>"))))))
|
||||
|
||||
;; POST /posts -> create from JSON {slug,title,body}. 409 if it exists.
|
||||
(define host/blog-create
|
||||
(fn (req)
|
||||
@@ -151,6 +166,7 @@
|
||||
;; pattern matches any single-segment path, so domain routes take precedence).
|
||||
(define host/blog-routes
|
||||
(list
|
||||
(dream-get "/" host/blog-home)
|
||||
(dream-get "/posts" host/blog-index)
|
||||
(dream-get "/:slug" host/blog-post)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user