Skip to content

Commit 2ac8b6c

Browse files
committed
Clean up the protocol between the builder and the page renderer
1 parent 49e1ab7 commit 2ac8b6c

File tree

3 files changed

+30
-47
lines changed

3 files changed

+30
-47
lines changed

blog/build.rkt

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,15 @@
88
racket/match
99
racket/path
1010
racket/promise
11-
racket/runtime-path
1211
racket/sequence
13-
(only-in megaparsack parse-result!)
14-
(only-in megaparsack/text parse-string)
15-
(only-in scribble/base title)
1612
scribble/base-render
17-
(only-in scribble/core document-date style)
1813
scribble/xref
1914
setup/xref
2015
threading
2116
(only-in xml write-xexpr)
2217

23-
(only-in "markdown/parse.rkt" document/p)
2418
"markdown/post.rkt"
25-
"markdown/to-scribble.rkt"
2619
"paths.rkt"
27-
"lang/metadata.rkt"
2820
"build/metadata.rkt"
2921
"build/render/scribble.rkt"
3022
"build/render/page.rkt")
@@ -143,28 +135,22 @@
143135
out-path
144136
(λ~>> (write-html (post-page info)))))
145137

146-
(define (build-post-index total-pages number deps+infos)
138+
(define (build-post-index total-pages number posts)
147139
(define base-path (index-path number #:file? #t))
148140
(define out-path (reroot-path base-path output-dir))
149141
(eprintf "~a rendering <output>~a\n" (timestamp-string) base-path)
150-
(define paths+infos (for/list ([dep+info (in-list deps+infos)])
151-
(match-define (list dep info) dep+info)
152-
(list (output-path->absolute-url (post-dep-page-path dep)) info)))
153142
(call-with-output-file* #:exists 'truncate/replace
154143
out-path
155-
(λ~>> (write-html (post-index-page total-pages number paths+infos)))))
144+
(λ~>> (write-html (post-index-page total-pages number posts)))))
156145

157-
(define (build-tag-index total-pages page-number tag deps+infos)
146+
(define (build-tag-index total-pages page-number tag posts)
158147
(define base-path (tag-index-path tag page-number))
159148
(define out-path (reroot-path base-path output-dir))
160149
(eprintf "~a rendering <output>~a\n" (timestamp-string) base-path)
161-
(define paths+infos (for/list ([dep+info (in-list deps+infos)])
162-
(match-define (list dep info) dep+info)
163-
(list (output-path->absolute-url (post-dep-page-path dep)) info)))
164150
(make-parent-directory* out-path)
165151
(call-with-output-file* #:exists 'truncate/replace
166152
out-path
167-
(λ~>> (write-html (tag-index-page total-pages page-number tag paths+infos)))))
153+
(λ~>> (write-html (tag-index-page total-pages page-number tag posts)))))
168154

169155
(define (build-all)
170156
(make-directory* build-dir)
@@ -176,23 +162,21 @@
176162
info))
177163

178164
(define total-pages (ceiling (/ (length all-post-deps) num-posts-per-page)))
179-
(for ([deps+infos (in-slice num-posts-per-page (reverse (map list all-post-deps post-infos)))]
165+
(for ([posts (in-slice num-posts-per-page (reverse post-infos))]
180166
[number (in-naturals 1)])
181-
(build-post-index total-pages number deps+infos))
182-
183-
(define tagged-deps+infos
184-
(for/fold ([tagged-deps+infos (hash)])
185-
([dep (in-list all-post-deps)]
186-
[info (in-list post-infos)]
187-
#:when #t
188-
[tag (in-list (rendered-post-tags info))])
189-
(hash-update tagged-deps+infos tag (λ~>> (cons (list dep info))) '())))
190-
191-
(for ([(tag deps+infos) (in-immutable-hash tagged-deps+infos)])
192-
(define total-pages (ceiling (/ (length deps+infos) num-posts-per-page)))
193-
(for ([deps+infos (in-slice num-posts-per-page deps+infos)]
167+
(build-post-index total-pages number posts))
168+
169+
(define tagged-posts
170+
(for*/fold ([tagged-deps+infos (hash)])
171+
([post (in-list post-infos)]
172+
[tag (in-list (rendered-post-tags post))])
173+
(hash-update tagged-deps+infos tag (λ~>> (cons post)) '())))
174+
175+
(for ([(tag posts) (in-immutable-hash tagged-posts)])
176+
(define total-pages (ceiling (/ (length posts) num-posts-per-page)))
177+
(for ([posts (in-slice num-posts-per-page posts)]
194178
[page-number (in-naturals 1)])
195-
(build-tag-index total-pages page-number tag deps+infos))))
179+
(build-tag-index total-pages page-number tag posts))))
196180

197181
(parameterize ([current-directory "/home/alexis/code/blog2"])
198182
(build-all))

blog/build/render/page.rkt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
[post-page (-> rendered-post? xexpr?)]
1818
[post-index-page (->i ([total-pages (and/c exact-integer? (>=/c 1))]
1919
[page-number (total-pages) (and/c exact-integer? (>=/c 1) (<=/c total-pages))]
20-
[paths+infos (listof (list/c string? rendered-post?))])
20+
[posts (listof rendered-post?)])
2121
[result xexpr?])]
2222
[tag-index-page (->i ([total-pages (and/c exact-integer? (>=/c 1))]
2323
[page-number (total-pages) (and/c exact-integer? (>=/c 1) (<=/c total-pages))]
2424
[tag string?]
25-
[paths+infos (listof (list/c string? rendered-post?))])
25+
[posts (listof rendered-post?)])
2626
[result xexpr?])]))
2727

2828
(define (page #:title title #:body body)
@@ -64,18 +64,18 @@
6464
,(build-post-header title date tags)
6565
,@body))))
6666

67-
(define (post-index-page total-pages page-number paths+infos)
67+
(define (post-index-page total-pages page-number posts)
6868
(page #:title "Alexis King’s Blog"
6969
#:body `(div ([class "content"])
70-
,@(build-post-index index-path total-pages page-number paths+infos))))
70+
,@(build-post-index index-path total-pages page-number posts))))
7171

72-
(define (tag-index-page total-pages page-number tag paths+infos)
72+
(define (tag-index-page total-pages page-number tag posts)
7373
(page #:title (~a "Posts tagged ‘" tag "")
7474
#:body `(div ([class "content"])
7575
(h1 ([class "tag-page-header"])
7676
"Posts tagged " (em ,tag))
7777
,@(build-post-index (λ~>> (tag-index-path tag))
78-
total-pages page-number paths+infos))))
78+
total-pages page-number posts))))
7979

8080
(define (build-post-header title date tags)
8181
(define date-str (post-date->string date))
@@ -88,10 +88,9 @@
8888
`(a ([href ,(tag-index-path tag)]) ,tag))
8989
(add-between ", ")))))
9090

91-
(define (build-post-index page-path total-pages page-number paths+infos)
92-
`[,@(for/list ([path+info (in-list paths+infos)])
93-
(match-define (list path info) path+info)
94-
(build-post-index-entry path info))
91+
(define (build-post-index page-path total-pages page-number posts)
92+
`[,@(for/list ([post (in-list posts)])
93+
(build-post-index-entry post))
9594
(ul ([class "pagination"])
9695
,(if (= page-number 1)
9796
'(li ([class "disabled"]) "")
@@ -105,8 +104,9 @@
105104
'(li ([class "disabled"]) "")
106105
`(li (a ([href ,(page-path (add1 page-number))]) ""))))])
107106

108-
(define (build-post-index-entry path info)
109-
(match-define (rendered-post _ title date tags body) info)
107+
(define (build-post-index-entry post)
108+
(match-define (rendered-post _ title date tags body) post)
109+
(define path (rendered-post-path post))
110110
`(article ([class "inline"])
111111
,(build-post-header `[(a ([href ,path]) ,@title)] date tags)
112112
; only render up to the start of the first section

blog/build/serve.rkt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#lang racket/base
22

3-
(require racket/runtime-path
4-
web-server/http/empty
3+
(require web-server/http/empty
54
web-server/servlet-env
65
"../paths.rkt")
76

0 commit comments

Comments
 (0)