chore: cleanup
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.management import call_command
|
||||
from web.models import WebSettings
|
||||
|
||||
|
||||
@dataclass
|
||||
class Color:
|
||||
name: str
|
||||
index: int
|
||||
value: str
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Usage:
|
||||
|
||||
python manage.py build_tailwind_theme
|
||||
"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
web_settings = WebSettings.load()
|
||||
path = os.path.join(settings.BASE_DIR, "theme", "static", "css", "main.css")
|
||||
|
||||
colors = []
|
||||
for color_name, data in web_settings.theme_colors.items():
|
||||
for index, value in data.items():
|
||||
color = Color(color_name, index, value)
|
||||
colors.append(color)
|
||||
|
||||
result = str(
|
||||
render_to_string(
|
||||
"theme/main.css.template",
|
||||
context={"colors": colors},
|
||||
)
|
||||
)
|
||||
with open(path, "w") as f:
|
||||
f.write(result)
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"tailwindcss",
|
||||
"-i",
|
||||
"theme/static/css/main.css",
|
||||
"-o",
|
||||
"theme/static/css/styles.css",
|
||||
"--minify",
|
||||
]
|
||||
)
|
||||
call_command("collectstatic", "--no-input")
|
||||
Reference in New Issue
Block a user