|
9 | 9 | racket/path |
10 | 10 | racket/promise |
11 | 11 | racket/sequence |
| 12 | + racket/serialize |
12 | 13 | scribble/base-render |
13 | 14 | scribble/xref |
14 | 15 | setup/xref |
|
38 | 39 | (path-replace-extension #".sxref") |
39 | 40 | (build-path build-dir _))) |
40 | 41 |
|
41 | | -(define (post-dep-page-path dep) |
42 | | - (match-define (regexp #px"^(\\d{4})-(\\d{2})-(\\d{2})-(.+)$" (list _ year month day slug)) |
43 | | - (path->string (path-replace-extension (file-name-from-path (post-dep-src-path dep)) #""))) |
44 | | - (build-path output-dir "blog" year month day slug "index.html")) |
45 | | - |
46 | | -(define (output-path->absolute-url path) |
47 | | - (define rooted-path (build-path "/" (find-relative-path output-dir path))) |
48 | | - (path->string (if (equal? (path->string (file-name-from-path rooted-path)) "index.html") |
49 | | - (path-only rooted-path) |
50 | | - rooted-path))) |
51 | | - |
52 | 42 | (define (markdown-post file-name) |
53 | 43 | (define path (build-path posts-dir file-name)) |
54 | 44 | (define main-part-promise (delay (parse-markdown-post (file->string path) path))) |
|
100 | 90 | (write-xexpr xexpr out)) |
101 | 91 |
|
102 | 92 | (define (build-post-body dep) |
103 | | - (eprintf "~a running <posts>/~a\n" (timestamp-string) (find-relative-path posts-dir (post-dep-src-path dep))) |
104 | | - (define renderer (new (render-mixin render%) |
105 | | - [dest-dir build-dir])) |
106 | | - (define main-parts (list (post-dep-main-part dep))) |
107 | | - (define out-paths (list (post-dep-info-path dep))) |
108 | | - |
109 | | - (define traverse-info (send renderer traverse main-parts out-paths)) |
110 | | - (define collect-info (send renderer collect main-parts out-paths traverse-info)) |
111 | | - (xref-transfer-info renderer collect-info (load-collections-xref)) |
112 | | - (define resolve-info (send renderer resolve main-parts out-paths collect-info)) |
113 | | - |
114 | | - (match-define (list (? rendered-post? post-info)) |
115 | | - (send renderer render main-parts out-paths resolve-info)) |
116 | | - |
117 | | - (define out-info (send renderer serialize-info resolve-info)) |
118 | | - (call-with-output-file* #:exists 'truncate/replace |
119 | | - (post-dep-xref-path dep) |
120 | | - (λ~>> (write out-info))) |
121 | | - |
122 | | - (define undefined-tags (send renderer get-undefined resolve-info)) |
123 | | - (unless (empty? undefined-tags) |
124 | | - (eprintf "Warning: some cross references may be broken due to undefined tags:\n") |
125 | | - (for ([tag (in-list undefined-tags)]) |
126 | | - (eprintf " ~s\n" tag))) |
127 | | - |
128 | | - post-info) |
| 93 | + (define src-mod-time (file-or-directory-modify-seconds (post-dep-src-path dep) #f (λ () #f))) |
| 94 | + (define info-mod-time (file-or-directory-modify-seconds (post-dep-info-path dep) #f (λ () #f))) |
| 95 | + (cond |
| 96 | + [(and src-mod-time info-mod-time (> info-mod-time src-mod-time)) |
| 97 | + (deserialize (call-with-input-file* (post-dep-info-path dep) read))] |
| 98 | + [else |
| 99 | + (eprintf "~a running <posts>/~a\n" (timestamp-string) (find-relative-path posts-dir (post-dep-src-path dep))) |
| 100 | + (define renderer (new (render-mixin render%) |
| 101 | + [dest-dir build-dir])) |
| 102 | + (define main-parts (list (post-dep-main-part dep))) |
| 103 | + (define out-paths (list (post-dep-info-path dep))) |
| 104 | + |
| 105 | + (define traverse-info (send renderer traverse main-parts out-paths)) |
| 106 | + (define collect-info (send renderer collect main-parts out-paths traverse-info)) |
| 107 | + (xref-transfer-info renderer collect-info (load-collections-xref)) |
| 108 | + (define resolve-info (send renderer resolve main-parts out-paths collect-info)) |
| 109 | + |
| 110 | + (match-define (list (? rendered-post? post-info)) |
| 111 | + (send renderer render main-parts out-paths resolve-info)) |
| 112 | + |
| 113 | + (define out-info (send renderer serialize-info resolve-info)) |
| 114 | + (call-with-output-file* #:exists 'truncate/replace |
| 115 | + (post-dep-xref-path dep) |
| 116 | + (λ~>> (write out-info))) |
| 117 | + |
| 118 | + (define undefined-tags (send renderer get-undefined resolve-info)) |
| 119 | + (unless (empty? undefined-tags) |
| 120 | + (eprintf "Warning: some cross references may be broken due to undefined tags:\n") |
| 121 | + (for ([tag (in-list undefined-tags)]) |
| 122 | + (eprintf " ~s\n" tag))) |
| 123 | + |
| 124 | + post-info])) |
129 | 125 |
|
130 | 126 | (define (build-post-page dep info) |
131 | | - (define out-path (post-dep-page-path dep)) |
132 | | - (eprintf "~a rendering <output>/~a\n" (timestamp-string) (find-relative-path output-dir out-path)) |
| 127 | + (define site-path (rendered-post-path info #:file? #t)) |
| 128 | + (define out-path (reroot-path site-path output-dir)) |
| 129 | + (eprintf "~a rendering <output>~a\n" (timestamp-string) site-path) |
133 | 130 | (make-parent-directory* out-path) |
134 | 131 | (call-with-output-file* #:exists 'truncate/replace |
135 | 132 | out-path |
136 | 133 | (λ~>> (write-html (post-page info))))) |
137 | 134 |
|
138 | 135 | (define (build-post-index total-pages number posts) |
139 | | - (define base-path (index-path number #:file? #t)) |
140 | | - (define out-path (reroot-path base-path output-dir)) |
141 | | - (eprintf "~a rendering <output>~a\n" (timestamp-string) base-path) |
| 136 | + (define site-path (index-path number #:file? #t)) |
| 137 | + (eprintf "~a rendering <output>~a\n" (timestamp-string) site-path) |
142 | 138 | (call-with-output-file* #:exists 'truncate/replace |
143 | | - out-path |
| 139 | + (reroot-path site-path output-dir) |
144 | 140 | (λ~>> (write-html (post-index-page total-pages number posts))))) |
145 | 141 |
|
146 | 142 | (define (build-tag-index total-pages page-number tag posts) |
147 | | - (define base-path (tag-index-path tag page-number)) |
148 | | - (define out-path (reroot-path base-path output-dir)) |
149 | | - (eprintf "~a rendering <output>~a\n" (timestamp-string) base-path) |
| 143 | + (define site-path (tag-index-path tag page-number)) |
| 144 | + (define out-path (reroot-path site-path output-dir)) |
| 145 | + (eprintf "~a rendering <output>~a\n" (timestamp-string) site-path) |
150 | 146 | (make-parent-directory* out-path) |
151 | 147 | (call-with-output-file* #:exists 'truncate/replace |
152 | 148 | out-path |
|
178 | 174 | [page-number (in-naturals 1)]) |
179 | 175 | (build-tag-index total-pages page-number tag posts)))) |
180 | 176 |
|
181 | | -(parameterize ([current-directory "/home/alexis/code/blog2"]) |
| 177 | +(module+ main |
182 | 178 | (build-all)) |
0 commit comments