Fix: "Cache-busting" for static files

This commit is contained in:
Cadence Ember 2022-10-30 23:56:25 +13:00
parent d3c5498d47
commit 63d37d5e4f
Signed by untrusted user: cadence
GPG key ID: BC1C2C61CF521B17

18
src/static-data.rkt Normal file
View file

@ -0,0 +1,18 @@
#lang typed/racket/base
(require racket/path
racket/runtime-path)
(provide
get-static-url)
(define-runtime-path path-static "../static")
(define static-data
(for/hash ([f (directory-list path-static)]) : (Immutable-HashTable Path Nonnegative-Integer)
(define built (simple-form-path (build-path path-static f)))
(values built (file-or-directory-modify-seconds built))))
(: get-static-url ((U String Path) -> String))
(define (get-static-url path-or-filename)
(define the-path (simple-form-path (if (path? path-or-filename) path-or-filename (build-path path-static path-or-filename))))
(format "/static/~a?t=~a" (file-name-from-path the-path) (hash-ref static-data the-path)))