|
24 | 24 | (only-in xml write-xexpr xexpr/c) |
25 | 25 |
|
26 | 26 | "../../lang/post-language.rkt" |
| 27 | + "../../paths.rkt" |
27 | 28 | "../metadata.rkt" |
28 | 29 | "highlight/pygments.rkt" |
29 | 30 | "util.rkt") |
|
85 | 86 | (λ (tag) (tag->query-string tag))))) |
86 | 87 |
|
87 | 88 | ; values associated with tags during the collect pass |
88 | | -(struct blog-post (title path) #:prefab) |
89 | | -(struct blog-post-anchor (title path anchor) #:prefab) |
| 89 | +(serializable-struct blog-page (title path) #:transparent |
| 90 | + #:guard (struct-guard/c content? site-path?)) |
| 91 | +(serializable-struct blog-page-anchor (title path anchor) #:transparent |
| 92 | + #:guard (struct-guard/c content? site-path? string?)) |
90 | 93 |
|
91 | 94 | (define header-depth->html-tag |
92 | 95 | (match-lambda |
|
151 | 154 | fns)) |
152 | 155 |
|
153 | 156 | (define/overment (render-one part ri output-file) |
154 | | - (parameterize ([current-output-file output-file]) |
| 157 | + (parameterize ([current-output-file output-file] |
| 158 | + [current-top-part part]) |
155 | 159 | (inner/hijack render-one part ri output-file))) |
156 | 160 |
|
157 | 161 | (define/override (render-nested-flow i part ri starting-item?) |
|
175 | 179 | (define/override (set-external-tag-path p) |
176 | 180 | (set! external-tag-path (string->url p))) |
177 | 181 |
|
| 182 | + ;; Returns the (absolute) path portion of the URL for the page that contains |
| 183 | + ;; the part currently being rendered. |
| 184 | + (define/public (get-current-site-path) |
| 185 | + (path->string (build-path "/" (find-relative-path (get-dest-directory) |
| 186 | + (current-output-file))))) |
| 187 | + |
178 | 188 | ;; ------------------------------------------------------------------------- |
179 | 189 | ;; collect |
180 | 190 |
|
|
183 | 193 | ; racket doc reference; index 4 corresponds to `whole-page?` |
184 | 194 | [(? vector? dest) (vector-ref dest 4)] |
185 | 195 | ; blog references |
186 | | - [(? blog-post?) #t] |
187 | | - [(? blog-post-anchor?) #f])) |
| 196 | + [(? blog-page?) #t] |
| 197 | + [(? blog-page-anchor?) #f])) |
188 | 198 |
|
189 | 199 | (define/public (current-part-whole-page? d) |
190 | 200 | (eq? d (current-top-part))) |
|
199 | 209 | (define/override (collect-part-tags d ci number) |
200 | 210 | (for ([t (part-tags d)]) |
201 | 211 | (define key (generate-tag t ci)) |
202 | | - (define title (or (part-title-content d) '("???"))) |
| 212 | + (define title (or (part-title-content d) "???")) |
203 | 213 | (collect-put! ci key |
204 | 214 | (if (current-part-whole-page? d) |
205 | | - (blog-post title (current-output-file)) |
206 | | - (blog-post-anchor title |
207 | | - (current-output-file) |
| 215 | + (blog-page title (get-current-site-path)) |
| 216 | + (blog-page-anchor title |
| 217 | + (get-current-site-path) |
208 | 218 | (tag->anchor-name (add-current-tag-prefix key))))))) |
209 | 219 |
|
210 | 220 | (define/override (collect-target-element i ci) |
211 | 221 | (define key (generate-tag (target-element-tag i) ci)) |
212 | 222 | (when (redirect-target-element? i) |
213 | 223 | (raise-arguments-error 'collect-target-element "redirect targets not supported" |
214 | 224 | "element" i)) |
215 | | - (collect-put! ci key (blog-post-anchor #f |
216 | | - (current-output-file) |
| 225 | + (collect-put! ci key (blog-page-anchor #f |
| 226 | + (get-current-site-path) |
217 | 227 | (tag->anchor-name (add-current-tag-prefix key))))) |
218 | 228 |
|
219 | 229 | (define/override (resolve-content i d ri) |
|
248 | 258 |
|
249 | 259 | (define/override (render-part-content part ri) |
250 | 260 | (define number (collected-info-number (part-collected-info part ri))) |
| 261 | + (define anchors (for/list ([tag (in-list (part-tags part))]) |
| 262 | + `(a ([name ,(tag->anchor-name |
| 263 | + (add-current-tag-prefix |
| 264 | + (tag-key tag ri)))])))) |
251 | 265 | (define title |
252 | 266 | (when/list (not (part-style? part 'hidden)) |
253 | 267 | `(,(header-depth->html-tag (number-depth number)) |
| 268 | + ,@anchors |
254 | 269 | ,@(cond/list |
255 | 270 | [(part-title-content part) |
256 | 271 | => (λ (title-content) (render-content title-content part ri))])))) |
|
280 | 295 | (define title-content |
281 | 296 | (match (resolve-get part ri tag) |
282 | 297 | [(vector title _ ...) title] |
283 | | - [(blog-post title _) title] |
284 | | - [(blog-post-anchor title _ _) title])) |
| 298 | + [(blog-page title _) title] |
| 299 | + [(blog-page-anchor title _ _) title] |
| 300 | + [#f "???"])) |
285 | 301 | (render-content title-content part ri)) |
286 | 302 |
|
287 | 303 | (define/override (render-content elem part ri) |
|
357 | 373 | (url-query external-tag-path))) |
358 | 374 | (url->string (struct-copy url external-tag-path [query redirect-query]))] |
359 | 375 |
|
360 | | - [(blog-post _ path) |
361 | | - (relative-path->relative-url-string |
362 | | - (find-relative-path (get-dest-directory) path))] |
| 376 | + [(blog-page _ path) |
| 377 | + (site-path->url-string path)] |
363 | 378 |
|
364 | | - [(blog-post-anchor _ path anchor) |
365 | | - (define file-path path) |
366 | | - (define fragment (string-append "#" (uri-encode anchor))) |
367 | | - (if (equal? file-path (current-output-file)) |
368 | | - fragment |
369 | | - (string-append (relative-path->relative-url-string |
370 | | - (find-relative-path (get-dest-directory) file-path)) |
371 | | - fragment))])) |
| 379 | + [(blog-page-anchor _ path anchor) |
| 380 | + (if (equal? path (get-current-site-path)) |
| 381 | + (string-append "#" (uri-encode anchor)) |
| 382 | + (site-path->url-string path #:fragment anchor))])) |
372 | 383 |
|
373 | 384 | (define attrs* (attributes-union (hasheq 'href href) attrs)) |
374 | 385 | (wrap-for-style #:attrs (hasheq) `[(a ,(attributes->list attrs*) ,@rendered)])] |
|
501 | 512 | ; files containing serialized `rendered-post` structures, instead. |
502 | 513 | (define/override (get-suffix) #".info") |
503 | 514 |
|
| 515 | + (define/override (get-current-site-path) |
| 516 | + (define part (current-top-part)) |
| 517 | + (post-path (get-required-style-prop post-date? (style-properties (part-style part))) |
| 518 | + (content->string (strip-aux (part-title-content part))))) |
| 519 | + |
504 | 520 | (define/override (render-one part ri output-file) |
505 | 521 | (define props (style-properties (part-style part))) |
506 | 522 | (define title-str (content->string (strip-aux (part-title-content part)) this part ri)) |
|
0 commit comments