stub make-index and add support to hx/ resource endpoints
This commit is contained in:
parent
8dffcd36d4
commit
f9baec0fd8
5 changed files with 87 additions and 12 deletions
|
@ -1,6 +1,8 @@
|
|||
#lang racket
|
||||
|
||||
(require racket/date
|
||||
(only-in racket/list first second third rest)
|
||||
(only-in racket/string string-prefix? string-replace)
|
||||
net/url
|
||||
xml
|
||||
web-server/web-server
|
||||
|
@ -11,7 +13,8 @@
|
|||
(prefix-in filter: web-server/dispatchers/dispatch-filter)
|
||||
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
|
||||
web-server/dispatchers/filesystem-map
|
||||
web-server/http)
|
||||
web-server/http
|
||||
csv-reading)
|
||||
|
||||
(define-namespace-anchor anc)
|
||||
(define ns (namespace-anchor->namespace anc))
|
||||
|
@ -70,6 +73,23 @@
|
|||
(string->bytes/utf-8
|
||||
(xexpr->string (read (open-input-file file)))))
|
||||
|
||||
(define (build-index res)
|
||||
;; get all the entries in res table
|
||||
;; build index
|
||||
(let* ([table (csv->list (open-input-file
|
||||
(path-add-extension
|
||||
(build-path "data" res)
|
||||
#".csv")))]
|
||||
[make-index
|
||||
(read (open-input-file "data/make-index.txt"))]
|
||||
[index ((eval make-index ns) res (rest table))])
|
||||
(lambda (req)
|
||||
(if (equal? res "tagged")
|
||||
'()
|
||||
(html-response
|
||||
(string->bytes/utf-8
|
||||
(xexpr->string index)))))))
|
||||
|
||||
(define (404-hx request)
|
||||
(html-response (xexpr-file->xml "source/not-found.txt")))
|
||||
|
||||
|
@ -77,9 +97,9 @@
|
|||
(define-values (httpx-app reverse-httpx-uri)
|
||||
(dispatch-rules
|
||||
[("hx" "home") (respond-resource-with-processor "root" xexpr-file->xml)]
|
||||
[("hx" "settled") (respond-resource-with-processor "settled" xexpr-file->xml)]
|
||||
[("hx" "settled") (build-index "settled")]
|
||||
[("hx" "settled" (integer-arg)) (respond-resource-with-processor "settled" xexpr-file->xml)]
|
||||
[("hx" "unsettled") (respond-resource-with-processor "unsettled" xexpr-file->xml)]
|
||||
[("hx" "unsettled") (build-index "unsettled")]
|
||||
[("hx" "unsettled" (integer-arg)) (respond-resource-with-processor "unsettled" xexpr-file->xml)]
|
||||
[("hx" "tagged") (respond-resource-with-processor "tagged" xexpr-file->xml)]
|
||||
[("hx" "tagged" (string-arg)) (respond-resource-with-processor "tagged" xexpr-file->xml)]
|
||||
|
|
64
source/make-index.txt
Normal file
64
source/make-index.txt
Normal file
|
@ -0,0 +1,64 @@
|
|||
(lambda (res posts)
|
||||
(let ([article
|
||||
`(article
|
||||
,(cond
|
||||
[(equal? res "settled")
|
||||
'(hgroup (h1 "settled* thoughts")
|
||||
(p (em "*-ish, something like a portfolio of projects")))]
|
||||
[(equal? res "unsettled")
|
||||
'(hgroup (h1 "unsettled thoughts")
|
||||
(p (em "just doing some thinking aloud")))]
|
||||
;; if res is tagged, build index of tags
|
||||
[(equal? res "tagged")
|
||||
'(hgroup (h1 "all the tags")
|
||||
(p (em "you looking for a flavor of something?")))]
|
||||
[(string-prefix? res "tagged/")
|
||||
(let ([tag (string-replace res "tagged/" "#")])
|
||||
`(hgroup (h1 ,(~a "stuff what's tagged like \"~a\"" tag))
|
||||
(p (em (~a "everything (or maybe just some things) i've ever said about \"~a\"" tag)))))]
|
||||
[else
|
||||
'(hgroup (h1 "i'm lost")
|
||||
(p (em "you weren't meant to be here")))]))])
|
||||
(define (settled-post post)
|
||||
`((div ((class "post-preview"))
|
||||
(h4 ,(second post))
|
||||
(p ,(third post))
|
||||
(a ((href ,(~a "/settled/" (first post))))
|
||||
,(~a "go! to " (second post) " page")))))
|
||||
(define (unsettled-post post)
|
||||
`((div ((class "post-preview"))
|
||||
(h4 ,(second post))
|
||||
(p ,(third post))
|
||||
(a ((href ,(~a "/unsettled/" (first post))))
|
||||
,(~a "go! to " (second post) " page")))))
|
||||
(define (tag-post post)
|
||||
`((div ((class "post-preview"))
|
||||
(h4 ,(second post))
|
||||
(p ,(third post))
|
||||
(a ((href ,(~a "/tagged/" (first post))))
|
||||
,(~a "go! to " (second post) " page")))))
|
||||
(define (tagged-post post)
|
||||
`((div ((class "post-preview"))
|
||||
(h4 ,(second post))
|
||||
(p ,(third post))
|
||||
;; tagged posts will insert href instead of id
|
||||
(a ((href ,first post))
|
||||
,(~a "go! to " (second post) " page")))))
|
||||
|
||||
|
||||
(if
|
||||
(< 0 (length posts))
|
||||
(for-each
|
||||
(lambda (post)
|
||||
(set! article
|
||||
(append article
|
||||
(cond
|
||||
[(equal? res "settled") (settled-post post)]
|
||||
[(equal? res "unsettled") (unsettled-post post)]
|
||||
[(equal? res "tagged") (tag-post post)]
|
||||
[(string-prefix? res "tagged/") (tagged-post post)]))))
|
||||
posts)
|
||||
(set! article
|
||||
(append article
|
||||
`((p "there's nothing here yet")))))
|
||||
article))
|
|
@ -1,3 +0,0 @@
|
|||
(article
|
||||
(p
|
||||
"stubbed tagged page"))
|
|
@ -1,3 +0,0 @@
|
|||
(article
|
||||
(p
|
||||
"stubbed tagged page"))
|
|
@ -1,3 +0,0 @@
|
|||
(article
|
||||
(p
|
||||
"stubbed tagged page"))
|
Loading…
Reference in a new issue