Merge pull request #1994 from bookwyrm-social/theme-file

Adds custom compile management command
This commit is contained in:
Mouse Reeve 2022-03-04 17:58:46 -08:00 committed by GitHub
commit 723ec8d461
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 7 deletions

View file

@ -0,0 +1,32 @@
""" Compile themes """
import os
from django.contrib.staticfiles.utils import get_files
from django.contrib.staticfiles.storage import StaticFilesStorage
from django.core.files.base import ContentFile
from django.core.management.base import BaseCommand
import sass
from sass_processor.processor import SassProcessor
# pylint: disable=line-too-long
class Command(BaseCommand):
"""Compile themes"""
help = "Compile theme scss files"
# pylint: disable=no-self-use,unused-argument
def handle(self, *args, **options):
"""compile themes"""
storage = StaticFilesStorage()
theme_files = list(get_files(storage, location="css/themes"))
theme_files = [t for t in theme_files if t[-5:] == ".scss"]
for filename in theme_files:
path = storage.path(filename)
content = sass.compile(
filename=path,
include_paths=SassProcessor.include_paths,
)
basename, _ = os.path.splitext(path)
destination_filename = basename + ".css"
print(f"saving f{destination_filename}")
storage.save(destination_filename, ContentFile(content))

View file

@ -189,10 +189,6 @@ STATICFILES_FINDERS = [
SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r"^.+\.[s]{0,1}(?:a|c)ss$" SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r"^.+\.[s]{0,1}(?:a|c)ss$"
SASS_PROCESSOR_INCLUDE_DIRS = [
os.path.join(BASE_DIR, ".css-config-sample"),
]
# minify css is production but not dev # minify css is production but not dev
if not DEBUG: if not DEBUG:
SASS_OUTPUT_STYLE = "compressed" SASS_OUTPUT_STYLE = "compressed"

View file

@ -1,14 +1,14 @@
{% load layout %} {% load layout %}
{% load sass_tags %}
{% load i18n %} {% load i18n %}
{% load static %} {% load static %}
{% load sass_tags %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{% get_lang %}"> <html lang="{% get_lang %}">
<head> <head>
<title>{% block title %}BookWyrm{% endblock %} - {{ site.name }}</title> <title>{% block title %}BookWyrm{% endblock %} - {{ site.name }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{% sass_src 'css/themes/bookwyrm-light.scss' %}" rel="stylesheet" type="text/css" /> <link href="{% sass_src site_theme %}" rel="stylesheet" type="text/css" />
<link rel="search" type="application/opensearchdescription+xml" href="{% url 'opensearch' %}" title="{% blocktrans with site_name=site.name %}{{ site_name }} search{% endblocktrans %}" /> <link rel="search" type="application/opensearchdescription+xml" href="{% url 'opensearch' %}" title="{% blocktrans with site_name=site.name %}{{ site_name }} search{% endblocktrans %}" />

2
bw-dev
View file

@ -154,7 +154,7 @@ case "$CMD" in
--config dev-tools/.stylelintrc.js --config dev-tools/.stylelintrc.js
;; ;;
compilescss) compilescss)
runweb python manage.py compilescss runweb python manage.py compilethemes
runweb python manage.py collectstatic --no-input runweb python manage.py collectstatic --no-input
;; ;;
collectstatic_watch) collectstatic_watch)