host: blog home page GET / -> HTML post index, 179/179
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:
2026-06-19 19:29:06 +00:00
parent 85e0af83f6
commit 64985ff6f7
2 changed files with 31 additions and 1 deletions

View File

@@ -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)))

View File

@@ -99,6 +99,13 @@
(host-bl-test "list empty -> data:[]"
(contains? (dream-resp-body (host-bl-wapp (host-bl-send "GET" "/posts" nil ""))) "\"data\":[]")
true)
;; HTML home page when empty
(host-bl-test "home / -> 200 html"
(contains? (dream-resp-header (host-bl-wapp (host-bl-send "GET" "/" nil "")) "content-type") "text/html")
true)
(host-bl-test "empty home says no posts"
(contains? (dream-resp-body (host-bl-wapp (host-bl-send "GET" "/" nil ""))) "No posts yet")
true)
;; create requires auth
(host-bl-test "create no auth -> 401"
@@ -121,6 +128,13 @@
(host-bl-test "list shows created post"
(contains? (dream-resp-body (host-bl-wapp (host-bl-send "GET" "/posts" nil ""))) "Hello World")
true)
;; home page lists it with a link to /<slug>/
(host-bl-test "home lists post title"
(contains? (dream-resp-body (host-bl-wapp (host-bl-send "GET" "/" nil ""))) "Hello World")
true)
(host-bl-test "home links to the post"
(contains? (dream-resp-body (host-bl-wapp (host-bl-send "GET" "/" nil ""))) "href=\"/hello/\"")
true)
;; create duplicate -> 409
(host-bl-test "create duplicate -> 409"
(dream-status (host-bl-wapp (host-bl-send "POST" "/posts" "Bearer good"