Skip to content

Commit e583400

Browse files
committed
Add inter-post navigation to the end of post pages
1 parent 6475e37 commit e583400

File tree

3 files changed

+54
-15
lines changed

3 files changed

+54
-15
lines changed

blog/build.rkt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@
156156
(post-dep-info-path dep)
157157
#:xref-out (post-dep-xref-path dep))]))
158158

159-
(define (build-post-page dep info)
159+
(define (build-post-page info #:older older-info #:newer newer-info)
160160
(define site-path (rendered-post-path info #:file? #t))
161161
(define out-path (reroot-path site-path output-dir))
162162
(eprintf "~a rendering <output>~a\n" (timestamp-string) site-path)
163163
(make-parent-directory* out-path)
164-
(call-with-output-file* #:exists 'truncate/replace
165-
out-path
166-
(λ~>> (write-html (post-page info)))))
164+
(call-with-output-file*
165+
#:exists 'truncate/replace
166+
out-path
167+
(λ~>> (write-html (post-page info #:older older-info #:newer newer-info)))))
167168

168169
(define (build-index-page total-pages page-number posts #:tag [tag #f])
169170
(define site-path (index-path page-number #:tag tag #:file? #t))
@@ -210,11 +211,14 @@
210211
(define (build-all)
211212
(make-directory* build-dir)
212213
(make-directory* output-dir)
214+
213215
(define all-posts
214216
(for/list ([dep (in-list all-post-deps)])
215-
(define info (build-post-body dep))
216-
(build-post-page dep info)
217-
info))
217+
(build-post-body dep)))
218+
(for ([post (in-list all-posts)]
219+
[older-post (in-list (cons #f all-posts))]
220+
[newer-post (in-list (append (rest all-posts) (list #f)))])
221+
(build-post-page post #:older older-post #:newer newer-post))
218222

219223
(define total-pages (ceiling (/ (length all-post-deps) num-posts-per-page)))
220224
(for ([posts (in-slice num-posts-per-page (reverse all-posts))]

blog/build/render/page.rkt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
(provide (contract-out
1717
[page (->* [#:title string? #:body xexpr/c] [#:tag (or/c string? #f)] xexpr/c)]
1818
[standalone-page (-> #:title string? #:body (listof xexpr/c) xexpr/c)]
19-
[post-page (-> rendered-post? xexpr/c)]
19+
[post-page (-> rendered-post?
20+
#:older (or/c rendered-post? #f)
21+
#:newer (or/c rendered-post? #f) xexpr/c)]
2022
[index-page-title (->* [] [#:tag (or/c string? #f)] string?)]
2123
[index-page (->i ([total-pages exact-positive-integer?]
2224
[page-number (total-pages) (and/c exact-positive-integer? (<=/c total-pages))]
@@ -62,13 +64,22 @@
6264
#:body `(div ([class "content"])
6365
(article ([class "main"]) ,@body))))
6466

65-
(define (post-page info)
67+
(define (post-page info #:older older-info #:newer newer-info)
6668
(match-define (rendered-post title-str title date tags body) info)
6769
(page #:title title-str
6870
#:body `(div ([class "content"])
6971
(article ([class "main"])
7072
,(build-post-header title date tags)
71-
,@body))))
73+
,@body
74+
(ul ([class "post-navigation"])
75+
(li ([class "previous"])
76+
,@(when/list newer-info
77+
`(a ([href ,(rendered-post-path newer-info)])
78+
"" nbsp (span ([class "post-title"]) ,@(rendered-post-title newer-info)))))
79+
(li ([class "next"])
80+
,@(when/list older-info
81+
`(a ([href ,(rendered-post-path older-info)])
82+
(span ([class "post-title"]) ,@(rendered-post-title older-info)) nbsp ""))))))))
7283

7384
(define (index-page-title #:tag [tag #f])
7485
(~a (if tag (~a "Posts tagged ‘" tag "’ | ") "")

scss/application.scss

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ body > section[role=main] {
132132
}
133133
}
134134

135-
// TODO: Reimplement end-of-post navigation links.
136-
// &.main > footer {
137-
// max-width: $content-width-large;
138-
// }
139-
140135
// Code blocks and tables can also spill into the margins.
141136
& > pre, & > .table-wrapper {
142137
max-width: 100%;
@@ -154,6 +149,11 @@ body > section[role=main] {
154149
max-width: $content-width-max;
155150
}
156151
}
152+
153+
// End-of-post navigation links can spill far into the margins.
154+
& > .post-navigation {
155+
max-width: $content-width-max;
156+
}
157157
}
158158

159159
// Subscripts and superscripts should not disrupt line spacing.
@@ -406,6 +406,30 @@ article.main > footer {
406406
}
407407
}
408408

409+
.post-navigation {
410+
display: flex;
411+
flex-wrap: wrap;
412+
margin-top: 4em;
413+
padding: 0;
414+
415+
li {
416+
flex: 1 1 auto;
417+
list-style: none;
418+
margin-bottom: 1em;
419+
}
420+
421+
.previous {
422+
text-align: left;
423+
}
424+
.next {
425+
text-align: right;
426+
}
427+
428+
.post-title {
429+
font-style: italic;
430+
}
431+
}
432+
409433
div.figure, article.main > p > a {
410434
& > img {
411435
max-width: 100%;

0 commit comments

Comments
 (0)