blog/tblog/views/static.py

29 lines
697 B
Python
Raw Normal View History

2024-12-31 19:56:46 -05:00
from django.http import HttpResponse
from django.urls import path
from django.views.decorators.cache import cache_control
from tblog.settings import STATIC_DIR
def get_static_serve(path: str, content_type: str):
def x(request):
return HttpResponse(
open(STATIC_DIR / path, "rb").read(),
content_type=content_type
)
x.__name__ = path
return x
file_associations = {
"css": "text/css",
"js": "text/javascript"
}
urlpatterns = [path(i, cache_control(**{"max-age": 60 * 60 * 24 * 30})(get_static_serve(i, file_associations[i.split(".")[-1]]))) for i in [
"css/ace.css",
"css/blog.css",
2024-12-31 19:56:46 -05:00
"css/write.css",
"js/write.js"
]]