1
Fork 0

static: get rid of django-compress

This commit is contained in:
Motiejus Jakštys 2024-01-26 12:11:37 +02:00
parent d11cc5bd25
commit 7cec799cfa
11 changed files with 27 additions and 54 deletions

11
.gitignore vendored
View File

@ -1,13 +1,10 @@
/.direnv /.direnv
/.hugo_build.lock /static/style.css
/app/_static
/resources/_gen
/public
/result
__pycache__
db.sqlite3 db.sqlite3
vm.qcow2 vm.qcow2
__pycache__
/.pre-commit-config.yaml /.pre-commit-config.yaml
result

View File

@ -5,8 +5,7 @@ from os import environ
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
_DEBUG = bool(environ.get('E11SYNC_DEBUG', False)) _DEBUG = bool(environ.get('E11SYNC_DEBUG', False))
_COMPRESS_OFFLINE = bool(environ.get('E11SYNC_COMPRESS_OFFLINE', False)) _STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', BASE_DIR / '_static')
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static')
_GEOIP_PATH = environ.get('GEOIP_PATH') _GEOIP_PATH = environ.get('GEOIP_PATH')
if db := environ.get('E11SYNC_DATABASE_PATH'): if db := environ.get('E11SYNC_DATABASE_PATH'):
_DATABASE_PATH = db _DATABASE_PATH = db
@ -25,7 +24,6 @@ else:
if not environ.get("E11SYNC_DEBUG_PRINTED"): if not environ.get("E11SYNC_DEBUG_PRINTED"):
print("DEBUG={}".format(_DEBUG)) print("DEBUG={}".format(_DEBUG))
print(secret_key_msg) print(secret_key_msg)
print("COMPRESS_OFFLINE={}".format(_COMPRESS_OFFLINE))
print("STATIC_ROOT={}".format(_STATIC_ROOT)) print("STATIC_ROOT={}".format(_STATIC_ROOT))
print("GEOIP_PATH={}".format(_GEOIP_PATH)) print("GEOIP_PATH={}".format(_GEOIP_PATH))
print("DATABASE_PATH={}".format(_DATABASE_PATH)) print("DATABASE_PATH={}".format(_DATABASE_PATH))
@ -45,7 +43,6 @@ INTERNAL_IPS = ["127.0.0.1"]
# Application definition # Application definition
INSTALLED_APPS = (['debug_toolbar'] if DEBUG else []) + [ INSTALLED_APPS = (['debug_toolbar'] if DEBUG else []) + [
'compressor',
'e11sync.apps.E11SyncConfig', 'e11sync.apps.E11SyncConfig',
'signup.apps.SignupConfig', 'signup.apps.SignupConfig',
@ -115,34 +112,16 @@ STATIC_URL = 'static/'
STATICFILES_FINDERS = [ STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.AppDirectoriesFinder", "django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
] ]
STATIC_ROOT = _STATIC_ROOT _storage = 'django.contrib.staticfiles.storage'
STORAGES = {
# At the time of testing: "staticfiles": {
# main-full.css: 34K "BACKEND": _storage + ".ManifestStaticFilesStorage",
# main-mini.css: 49K },
# main-full.css.br: 5.0K
# main-mini.css.br: 7.1K
#
# Minifying those files will necessitate sourcemaps, which
# is not currently possible due to
# https://github.com/django-compressor/django-compressor/issues/438
# Since the savings with minification are not that huge, let's keep
# it a bir larger, but much simpler.
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = _COMPRESS_OFFLINE
COMPRESS_FILTERS = {
'css': [],
'js': [],
} }
COMPRESS_PRECOMPILERS = ( STATIC_ROOT = _STATIC_ROOT
('text/x-scss', 'sass --no-source-map {infile} {outfile}'),
)
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

View File

@ -0,0 +1 @@
../../../static/style.css

View File

@ -1,13 +1,11 @@
{% load compress static %} {% load static %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>{% block "title" %}11sync.net{% endblock %}</title> <title>{% block "title" %}11sync.net{% endblock %}</title>
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
{% compress css %} <link rel="stylesheet" type="text/css" href="{% static "style.css" %}">
<link rel="stylesheet" type="text/x-scss" href="{% static "style.scss" %}">
{% endcompress %}
<link rel="icon" href="data:;base64,iVBORw0KGgo="> <link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head> </head>
<body id="page-{% block "pagename" %}{% endblock %}"> <body id="page-{% block "pagename" %}{% endblock %}">

View File

@ -98,7 +98,6 @@
(python3.withPackages (python3.withPackages
(ps: [ (ps: [
ps.django ps.django
ps.django-compressor
ps.geoip2 ps.geoip2
ps.django-debug-toolbar ps.django-debug-toolbar

View File

@ -17,7 +17,6 @@
python3.withPackages python3.withPackages
(ps: [ (ps: [
ps.django ps.django
ps.django-compressor
ps.geoip2 ps.geoip2
]); ]);
in in
@ -51,13 +50,12 @@ in
--set E11SYNC_DATABASE_PATH "${databasePath}" \ --set E11SYNC_DATABASE_PATH "${databasePath}" \
''} \ ''} \
--set E11SYNC_STATIC_ROOT "${e11sync-static.passthru.manifest}" \ --set E11SYNC_STATIC_ROOT "${e11sync-static.passthru.manifest}" \
--set E11SYNC_COMPRESS_OFFLINE 1 \
--set E11SYNC_DEBUG "" \ --set E11SYNC_DEBUG "" \
--set GEOIP_PATH "${geoip-mmdb}" \ --set GEOIP_PATH "${geoip-mmdb}" \
''; '';
passthru.tests.unit = passthru.tests.unit =
runCommand "e11sync-test" { runCommand "e11sync-test" {
src = ../app; srcs = ../app;
buildInputs = [ buildInputs = [
pythonEnv pythonEnv
dart-sass dart-sass
@ -66,6 +64,7 @@ in
unpackPhase unpackPhase
patchShebangs --build app/manage.py patchShebangs --build app/manage.py
export GEOIP_PATH="${geoip-mmdb}" export GEOIP_PATH="${geoip-mmdb}"
export E11SYNC_STATIC_ROOT="${e11sync-static.passthru.manifest}"
app/manage.py test app app/manage.py test app
mkdir -p $out mkdir -p $out
''; '';

View File

@ -9,33 +9,31 @@
}: let }: let
self = stdenv.mkDerivation { self = stdenv.mkDerivation {
name = "e11sync-static"; name = "e11sync-static";
src = ../app; srcs = [../app ../static];
sourceRoot = ".";
nativeBuildInputs = [ nativeBuildInputs = [
python3Packages.django python3Packages.django
python3Packages.django-compressor
dart-sass dart-sass
findutils findutils
]; ];
patchPhase = ''patchShebangs --build manage.py''; patchPhase = ''patchShebangs --build app/manage.py'';
buildPhase = '' buildPhase = ''
export E11SYNC_STATIC_ROOT=$PWD/static
export E11SYNC_DEBUG= export E11SYNC_DEBUG=
export E11SYNC_COMPRESS_OFFLINE=1 make -C static style.css
./manage.py collectstatic app/manage.py collectstatic
./manage.py compress
find static/ \ find app/_static \
-name '*.css' -or \ -name '*.css' -or \
-name '*.js' -or \ -name '*.js' -or \
-name '*.svg' | \ -name '*.svg' | \
tee >(xargs -n1 -P''$(nproc) ${zopfli}/bin/zopfli) | \ tee >(xargs -n1 -P''$(nproc) ${zopfli}/bin/zopfli) | \
xargs -n1 -P''$(nproc) ${brotli}/bin/brotli xargs -n1 -P''$(nproc) ${brotli}/bin/brotli
''; '';
installPhase = ''mv static $out''; installPhase = ''mv app/_static $out'';
passthru.manifest = runCommand "e11sync-static-manifest" {} '' passthru.manifest = runCommand "e11sync-static-manifest" {} ''
mkdir -p $out/CACHE mkdir -p $out
cp ${self}/CACHE/manifest.json $out/CACHE/ cp ${self}/staticfiles.json $out/
''; '';
}; };
in in

2
static/Makefile Normal file
View File

@ -0,0 +1,2 @@
style.css: style.scss grids-responsive.css pure.css
sass --no-source-map $< $@