clone url: git://git.m455.casa/m455.casa
src/generate-posts.scm
1 | (include "src/imports.scm") |
2 | (include "src/static.scm") |
3 | (include "src/utils.scm") |
4 | (include "src/parser.scm") |
5 |
|
6 | (define (path-data->html-link path-data) |
7 | (format " <li><a href=\"/~a\">~a</a></li>" |
8 | (pathname-replace-extension (alist-ref 'path path-data) "html") |
9 | (clean (alist-ref 'title path-data)))) |
10 |
|
11 | (define (create-posts-page paths-data) |
12 | (let* ((posts-list (map path-data->html-link paths-data)) |
13 | (html-contents (string-append |
14 | "<h1>posts</h1>\n" |
15 | "<p>here's a list of my blog posts. if you're looking for my older posts, then you\n" |
16 | "can find them in my <a href=\"/archive\">archive</a>.</p>\n" |
17 | "<ul>\n" |
18 | (string-intersperse posts-list "\n") |
19 | "\n</ul>"))) |
20 | (string-populate |
21 | HTML-TEMPLATE |
22 | `((title . "m455's posts") |
23 | (contents . ,html-contents))))) |
24 |
|
25 | (define (markup-file->html file) |
26 | (let ((lines (file->lines file))) |
27 | (string-populate |
28 | HTML-TEMPLATE |
29 | `((title . ,(substring (car lines) (string-length TITLE-PREFIX))) |
30 | (contents . ,(parse-lines lines 'normal)))))) |
31 |
|
32 | (define (generate-posts-page) |
33 | (let ((paths-data (paths->sorted-alists (directory POSTS-DIRECTORY))) |
34 | (posts-build-path (make-pathname BUILD-DIRECTORY POSTS-DIRECTORY))) |
35 | (create-directory posts-build-path #t) |
36 | (file-write (make-pathname posts-build-path "index.html") |
37 | (create-posts-page paths-data)))) |
38 |
|
39 | (define (generate-posts) |
40 | (for-each |
41 | (lambda (file) |
42 | (file-write (pathname-replace-extension |
43 | (make-pathname BUILD-DIRECTORY file) |
44 | "html") |
45 | (markup-file->html file))) |
46 | (map (lambda (path) (make-pathname POSTS-DIRECTORY path)) |
47 | (directory POSTS-DIRECTORY)))) |
48 |
|
49 | (define (main) |
50 | (generate-posts-page) |
51 | (generate-posts)) |
52 |
|
53 | (main) |