Skip to content

Commit 49e1ab7

Browse files
committed
Reorganize and clean up a lot of things
1 parent 476a94a commit 49e1ab7

File tree

15 files changed

+310
-222
lines changed

15 files changed

+310
-222
lines changed

blog/build.rkt

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@
1818
scribble/xref
1919
setup/xref
2020
threading
21+
(only-in xml write-xexpr)
2122

2223
(only-in "markdown/parse.rkt" document/p)
2324
"markdown/post.rkt"
2425
"markdown/to-scribble.rkt"
2526
"paths.rkt"
26-
(only-in "scribble/post-language.rkt" post-tags)
27-
"scribble/render.rkt")
27+
"lang/metadata.rkt"
28+
"build/metadata.rkt"
29+
"build/render/scribble.rkt"
30+
"build/render/page.rkt")
2831

2932
(define num-posts-per-page 10)
3033

31-
(define-runtime-path posts-dir "posts")
32-
33-
(define current-build-directory (make-parameter (string->path "build")))
34-
(define current-output-directory (make-parameter (string->path "output")))
35-
3634
(struct post-dep (src-path main-part-promise) #:transparent)
3735

3836
(define (post-dep-main-part dep)
@@ -41,20 +39,20 @@
4139
(define (post-dep-info-path dep)
4240
(~> (file-name-from-path (post-dep-src-path dep))
4341
(path-replace-extension #".info")
44-
(build-path (current-build-directory) _)))
42+
(build-path build-dir _)))
4543

4644
(define (post-dep-xref-path dep)
4745
(~> (file-name-from-path (post-dep-src-path dep))
4846
(path-replace-extension #".sxref")
49-
(build-path (current-build-directory) _)))
47+
(build-path build-dir _)))
5048

5149
(define (post-dep-page-path dep)
5250
(match-define (regexp #px"^(\\d{4})-(\\d{2})-(\\d{2})-(.+)$" (list _ year month day slug))
5351
(path->string (path-replace-extension (file-name-from-path (post-dep-src-path dep)) #"")))
54-
(build-path (current-output-directory) "blog" year month day slug "index.html"))
52+
(build-path output-dir "blog" year month day slug "index.html"))
5553

5654
(define (output-path->absolute-url path)
57-
(define rooted-path (build-path "/" (find-relative-path (current-output-directory) path)))
55+
(define rooted-path (build-path "/" (find-relative-path output-dir path)))
5856
(path->string (if (equal? (path->string (file-name-from-path rooted-path)) "index.html")
5957
(path-only rooted-path)
6058
rooted-path)))
@@ -105,10 +103,14 @@
105103
":" (pad (date-second now))
106104
"]"))
107105

106+
(define (write-html xexpr out)
107+
(display "<!doctype html>" out)
108+
(write-xexpr xexpr out))
109+
108110
(define (build-post-body dep)
109111
(eprintf "~a running <posts>/~a\n" (timestamp-string) (find-relative-path posts-dir (post-dep-src-path dep)))
110112
(define renderer (new (render-mixin render%)
111-
[dest-dir (current-build-directory)]))
113+
[dest-dir build-dir]))
112114
(define main-parts (list (post-dep-main-part dep)))
113115
(define out-paths (list (post-dep-info-path dep)))
114116

@@ -135,38 +137,38 @@
135137

136138
(define (build-post-page dep info)
137139
(define out-path (post-dep-page-path dep))
138-
(eprintf "~a rendering <output>/~a\n" (timestamp-string) (find-relative-path (current-output-directory) out-path))
140+
(eprintf "~a rendering <output>/~a\n" (timestamp-string) (find-relative-path output-dir out-path))
139141
(make-parent-directory* out-path)
140142
(call-with-output-file* #:exists 'truncate/replace
141143
out-path
142-
(λ~>> (render-post-page info))))
144+
(λ~>> (write-html (post-page info)))))
143145

144146
(define (build-post-index total-pages number deps+infos)
145147
(define base-path (index-path number #:file? #t))
146-
(define out-path (reroot-path base-path (current-output-directory)))
148+
(define out-path (reroot-path base-path output-dir))
147149
(eprintf "~a rendering <output>~a\n" (timestamp-string) base-path)
148150
(define paths+infos (for/list ([dep+info (in-list deps+infos)])
149151
(match-define (list dep info) dep+info)
150152
(list (output-path->absolute-url (post-dep-page-path dep)) info)))
151153
(call-with-output-file* #:exists 'truncate/replace
152154
out-path
153-
(λ~>> (render-post-index total-pages number paths+infos))))
155+
(λ~>> (write-html (post-index-page total-pages number paths+infos)))))
154156

155157
(define (build-tag-index total-pages page-number tag deps+infos)
156158
(define base-path (tag-index-path tag page-number))
157-
(define out-path (reroot-path base-path (current-output-directory)))
159+
(define out-path (reroot-path base-path output-dir))
158160
(eprintf "~a rendering <output>~a\n" (timestamp-string) base-path)
159161
(define paths+infos (for/list ([dep+info (in-list deps+infos)])
160162
(match-define (list dep info) dep+info)
161163
(list (output-path->absolute-url (post-dep-page-path dep)) info)))
162164
(make-parent-directory* out-path)
163165
(call-with-output-file* #:exists 'truncate/replace
164166
out-path
165-
(λ~>> (render-tag-index total-pages page-number tag paths+infos))))
167+
(λ~>> (write-html (tag-index-page total-pages page-number tag paths+infos)))))
166168

167169
(define (build-all)
168-
(make-directory* (current-build-directory))
169-
(make-directory* (current-output-directory))
170+
(make-directory* build-dir)
171+
(make-directory* output-dir)
170172
(define post-infos
171173
(for/list ([dep (in-list all-post-deps)])
172174
(define info (build-post-body dep))

blog/build/metadata.rkt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#lang racket/base
2+
3+
(require racket/contract
4+
racket/serialize
5+
(only-in xml xexpr?)
6+
7+
"../paths.rkt"
8+
"../lang/metadata.rkt")
9+
10+
(provide (struct-out rendered-post)
11+
(contract-out
12+
[rendered-post-path (-> rendered-post? site-path?)]))
13+
14+
(serializable-struct rendered-post (title-str title date tags body) #:transparent
15+
#:guard (struct-guard/c string?
16+
(listof xexpr?)
17+
post-date?
18+
(listof string?)
19+
(listof xexpr?)))
20+
21+
(define (rendered-post-path post #:file? [file? #f])
22+
(post-path (rendered-post-date post)
23+
(rendered-post-title-str post)
24+
#:file? file?))
File renamed without changes.

blog/build/render/page.rkt

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#lang racket/base
2+
3+
(require racket/contract
4+
racket/date
5+
racket/format
6+
racket/list
7+
racket/match
8+
threading
9+
(only-in xml xexpr?)
10+
11+
"../../lang/metadata.rkt"
12+
"../../paths.rkt"
13+
"../metadata.rkt")
14+
15+
(provide (contract-out
16+
[page (-> #:title string? #:body xexpr? xexpr?)]
17+
[post-page (-> rendered-post? xexpr?)]
18+
[post-index-page (->i ([total-pages (and/c exact-integer? (>=/c 1))]
19+
[page-number (total-pages) (and/c exact-integer? (>=/c 1) (<=/c total-pages))]
20+
[paths+infos (listof (list/c string? rendered-post?))])
21+
[result xexpr?])]
22+
[tag-index-page (->i ([total-pages (and/c exact-integer? (>=/c 1))]
23+
[page-number (total-pages) (and/c exact-integer? (>=/c 1) (<=/c total-pages))]
24+
[tag string?]
25+
[paths+infos (listof (list/c string? rendered-post?))])
26+
[result xexpr?])]))
27+
28+
(define (page #:title title #:body body)
29+
`(html
30+
(head
31+
(meta ([charset "utf-8"]))
32+
(meta ([name "viewport"] [content "width=device-width, initial-scale=1"]))
33+
(title ,title)
34+
,(stylesheet (~a "https://fonts.googleapis.com/css?family"
35+
"=Merriweather+Sans:400,300,300italic,400italic,700,700italic,800,800italic"
36+
"|Merriweather:400,300,300italic,400italic,700,700italic,900,900italic"
37+
"|Fira+Code:300,400,500,600,700"))
38+
,(stylesheet "/css/application.min.css")
39+
,(stylesheet "/css/pygments.min.css")
40+
(body
41+
(header
42+
(nav ([role "navigation"] [class "navigation-bar"])
43+
(ul ([class "navigation-items left"])
44+
(li ([class "blog-title-header"])
45+
(a ([href "/"]) "Alexis King")))
46+
(ul ([class "navigation-items center"]))
47+
(ul ([class "navigation-items right"])
48+
(li (a ([href "/"]) "Home"))
49+
(li (a ([href "/resume.html"]) "About Me")))))
50+
(section ([role "main"]) ,body)
51+
(footer
52+
(div ([class "copyright-notice"]) "© " ,(~a (date-year (current-date))) ", Alexis King")
53+
(div "Built with "
54+
(a ([href "https://docs.racket-lang.org/scribble/index.html"]) (strong "Scribble"))
55+
", the Racket document preparation system.")
56+
(div "Feeds are available via " (a ([href "/feeds/all.atom.xml"]) "Atom")
57+
" or " (a ([href "/feeds/all.rss.xml"]) "RSS") "."))))))
58+
59+
(define (post-page info)
60+
(match-define (rendered-post title-str title date tags body) info)
61+
(page #:title title-str
62+
#:body `(div ([class "content"])
63+
(article ([class "main"])
64+
,(build-post-header title date tags)
65+
,@body))))
66+
67+
(define (post-index-page total-pages page-number paths+infos)
68+
(page #:title "Alexis King’s Blog"
69+
#:body `(div ([class "content"])
70+
,@(build-post-index index-path total-pages page-number paths+infos))))
71+
72+
(define (tag-index-page total-pages page-number tag paths+infos)
73+
(page #:title (~a "Posts tagged ‘" tag "")
74+
#:body `(div ([class "content"])
75+
(h1 ([class "tag-page-header"])
76+
"Posts tagged " (em ,tag))
77+
,@(build-post-index (λ~>> (tag-index-path tag))
78+
total-pages page-number paths+infos))))
79+
80+
(define (build-post-header title date tags)
81+
(define date-str (post-date->string date))
82+
`(header
83+
(h1 ([class "title"]) ,@title)
84+
(div ([class "date-and-tags"])
85+
(time ([datetime ,date-str]) ,date-str)
86+
" " (span ([style "margin: 0 5px"]) "⦿") " "
87+
,@(~> (for/list ([tag (in-list tags)])
88+
`(a ([href ,(tag-index-path tag)]) ,tag))
89+
(add-between ", ")))))
90+
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))
95+
(ul ([class "pagination"])
96+
,(if (= page-number 1)
97+
'(li ([class "disabled"]) "")
98+
`(li (a ([href ,(page-path (sub1 page-number))]) "")))
99+
,@(for/list ([i (in-range 1 (add1 total-pages))])
100+
`(li ,(if (= i page-number)
101+
'([class "pagination-number active"])
102+
'([class "pagination-number"]))
103+
(a ([href ,(page-path i)]) ,(~a i))))
104+
,(if (= page-number total-pages)
105+
'(li ([class "disabled"]) "")
106+
`(li (a ([href ,(page-path (add1 page-number))]) ""))))])
107+
108+
(define (build-post-index-entry path info)
109+
(match-define (rendered-post _ title date tags body) info)
110+
`(article ([class "inline"])
111+
,(build-post-header `[(a ([href ,path]) ,@title)] date tags)
112+
; only render up to the start of the first section
113+
,@(takef body (match-lambda [(cons 'h2 _) #f] [_ #t]))
114+
(p (a ([href ,path]) (span ([class "read-more-text"]) "Read more") ""))))
115+
116+
(define (stylesheet href)
117+
`(link ([rel "stylesheet"] [type "text/css"] [href ,href])))

0 commit comments

Comments
 (0)