diff --git a/NOTES.md b/NOTES.md index eb7cdcc..d6545da 100644 --- a/NOTES.md +++ b/NOTES.md @@ -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 diff --git a/private/rules.rkt b/private/rules.rkt index 2d52d22..43eb206 100644 --- a/private/rules.rkt +++ b/private/rules.rkt @@ -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 compile-index-json - compile-webfinger)) + (set-union + (generate-post-render-rules) + (set compile-index-json + compile-webfinger))) (define ops (generate-operations compiler-rules)) (for ([op (in-list ops)]) diff --git a/scripts/init b/scripts/init index 2c2d2e8..1b92097 100755 --- a/scripts/init +++ b/scripts/init @@ -16,6 +16,7 @@ ; cache dirs (make-directory "cache") (make-directory "cache/actors") +(make-directory "cache/posts") ; db dirs (make-directory "db")