clone url: git://git.m455.casa/m455.casa
src/utils.scm
1 | (define (file->lines file) |
2 | (with-input-from-file file read-lines)) |
3 |
|
4 | (define (file-write file contents) |
5 | (with-output-to-file |
6 | file |
7 | (lambda () (display contents)))) |
8 |
|
9 | (define (pair->mustached-pair pair) |
10 | (let* ((first (car pair)) |
11 | (key (if (string? first) |
12 | first |
13 | (symbol->string first)))) |
14 | `(,(string-append "{{" key "}}") . ,(cdr pair)))) |
15 |
|
16 | (define (string-populate str smap) |
17 | (string-translate* |
18 | str |
19 | (map pair->mustached-pair smap))) |
20 |
|
21 | (define (path->alist path) |
22 | (let ((lines (file->lines path))) |
23 | `((date . ,(caddr lines)) |
24 | (path . ,path) |
25 | (title . ,(substring (car lines) (string-length TITLE-PREFIX)))))) |
26 |
|
27 | (define (paths->sorted-alists paths) |
28 | (let* ((relative-paths (map (lambda (path) |
29 | (make-pathname POSTS-DIRECTORY path)) |
30 | paths)) |
31 | (paths-data (map path->alist relative-paths))) |
32 | (sort paths-data |
33 | (lambda (data-a data-b) |
34 | (string>? (alist-ref 'date data-a) (alist-ref 'date data-b)))))) |
35 |
|