Minify pygments styles
This commit is contained in:
parent
fffd41dc82
commit
872fd4fc82
2 changed files with 8 additions and 12 deletions
|
@ -30,6 +30,7 @@ wagtail-lite-youtube-embed==0.1.0
|
|||
django-minify-html==1.7.1
|
||||
metadata-parser==0.12.1
|
||||
django-tasks==0.2.0
|
||||
lightningcss==0.2.0
|
||||
|
||||
# DRF OpenAPI dependencies
|
||||
uritemplate
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
import lightningcss
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.utils.datastructures import OrderedSet
|
||||
from django.views.decorators.cache import cache_control
|
||||
from pygments.formatters.html import HtmlFormatter
|
||||
|
||||
|
||||
@cache_control(max_age=3600)
|
||||
def pygments_styles(request: HttpRequest) -> HttpResponse:
|
||||
default_styles = (
|
||||
HtmlFormatter(style="default")
|
||||
.get_style_defs("html:not(.dark-mode) .highlight")
|
||||
.split("\n")
|
||||
default_styles = HtmlFormatter(style="default").get_style_defs(
|
||||
"html:not(.dark-mode) .highlight"
|
||||
)
|
||||
dark_styles = (
|
||||
HtmlFormatter(style="monokai")
|
||||
.get_style_defs("html.dark-mode .highlight")
|
||||
.split("\n")
|
||||
)
|
||||
return HttpResponse(
|
||||
"".join(OrderedSet(default_styles + dark_styles)), content_type="text/css"
|
||||
dark_styles = HtmlFormatter(style="monokai").get_style_defs(
|
||||
"html.dark-mode .highlight"
|
||||
)
|
||||
compressed = lightningcss.process_stylesheet(default_styles + dark_styles)
|
||||
return HttpResponse(compressed, content_type="text/css")
|
||||
|
|
Loading…
Reference in a new issue