render posts to html

This commit is contained in:
xenia 2020-05-09 02:37:19 -04:00
parent 6aed082015
commit 06515afc50
3 changed files with 33 additions and 2 deletions

View File

@ -50,6 +50,10 @@ inotify will be used to detect completion of a queued request
if a remote request fails after a reasonable retry interval, it may be aborted and the cache may
be filled in with dummy data indicating the resource could not be fetched
/cache/posts/ stores intermediate HTML-rendered posts generated from markdown. this avoids needing
to recompile posts from markdown multiple times because that's super unnecessary. it also contains
front matter with the post metadata and parsed hashtags
## Task queue
stores queued outgoing requests

View File

@ -136,9 +136,35 @@
'href instance-url))))
(write-json webfinger out))))
(define (generate-post-render-rules)
(define (make-post-cache-rule post-src post-dst)
(rule `("src/instance.rktd" ,post-src) post-dst
(lambda (in out)
(define prefs (prefs-load (hash-ref in "src/instance.rktd")))
(define instance-url (prefs-get prefs 'instance-url))
(define post-content (port->string (hash-ref in post-src)))
(define hashtags (mutable-set))
(define post-htmls (map (lambda (b)
(process-hashtags! b instance-url hashtags))
(parse-markdown post-content)))
(write `((is-meow #t)
(hashtags ,(set->list hashtags))) out)
(for ([item (in-list post-htmls)])
(write-string (xexpr->string item) out)))))
(for/fold ([posts (set)]) ([post-name (in-list (directory-list "src/posts"))]
#:when (regexp-match? #px"\\.md$" post-name))
(define post-src (build-path "src/posts" post-name))
(define cache-dst (build-path "cache/posts"
(path-replace-extension (last (explode-path post-src)) ".html")))
(set-add posts (make-post-cache-rule post-src cache-dst))))
(define compiler-rules
(set-union
(generate-post-render-rules)
(set compile-index-json
compile-webfinger))
compile-webfinger)))
(define ops (generate-operations compiler-rules))
(for ([op (in-list ops)])

View File

@ -16,6 +16,7 @@
; cache dirs
(make-directory "cache")
(make-directory "cache/actors")
(make-directory "cache/posts")
; db dirs
(make-directory "db")