diff --git a/articles/models.py b/articles/models.py index 8401d80..11ec6fa 100644 --- a/articles/models.py +++ b/articles/models.py @@ -1,7 +1,7 @@ import random import re import uuid -from functools import cached_property +from functools import cached_property, reduce import html2text import markdown @@ -153,3 +153,15 @@ class Article(AdminUrlMixin, models.Model): return list( filter(None, map(lambda k: k.strip().lower(), self.keywords.split(","))) ) + + @cached_property + def get_minified_custom_css(self): + def reducer(res, next_char): + if len(res) == 0: + return next_char + if res[-1] == next_char == " ": + return res + return res + next_char + + css = self.custom_css.replace("\n", " ") + return reduce(reducer, css, "") diff --git a/articles/templates/articles/article_detail.html b/articles/templates/articles/article_detail.html index 053c2ec..72f9fa9 100644 --- a/articles/templates/articles/article_detail.html +++ b/articles/templates/articles/article_detail.html @@ -2,7 +2,7 @@ {% block append_header %} {% endblock %} diff --git a/articles/templates/articles/article_list.html b/articles/templates/articles/article_list.html index 4a9e436..8eb3f5a 100644 --- a/articles/templates/articles/article_list.html +++ b/articles/templates/articles/article_list.html @@ -2,7 +2,7 @@ {% block append_header %}