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
/.hugo_build.lock
/resources/_gen
/public
/result
__pycache__
/static/style.css
/app/_static
db.sqlite3
vm.qcow2
__pycache__
/.pre-commit-config.yaml
result

View File

@ -5,8 +5,7 @@ from os import environ
BASE_DIR = Path(__file__).resolve().parent.parent
_DEBUG = bool(environ.get('E11SYNC_DEBUG', False))
_COMPRESS_OFFLINE = bool(environ.get('E11SYNC_COMPRESS_OFFLINE', False))
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static')
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', BASE_DIR / '_static')
_GEOIP_PATH = environ.get('GEOIP_PATH')
if db := environ.get('E11SYNC_DATABASE_PATH'):
_DATABASE_PATH = db
@ -25,7 +24,6 @@ else:
if not environ.get("E11SYNC_DEBUG_PRINTED"):
print("DEBUG={}".format(_DEBUG))
print(secret_key_msg)
print("COMPRESS_OFFLINE={}".format(_COMPRESS_OFFLINE))
print("STATIC_ROOT={}".format(_STATIC_ROOT))
print("GEOIP_PATH={}".format(_GEOIP_PATH))
print("DATABASE_PATH={}".format(_DATABASE_PATH))
@ -45,7 +43,6 @@ INTERNAL_IPS = ["127.0.0.1"]
# Application definition
INSTALLED_APPS = (['debug_toolbar'] if DEBUG else []) + [
'compressor',
'e11sync.apps.E11SyncConfig',
'signup.apps.SignupConfig',
@ -115,34 +112,16 @@ STATIC_URL = 'static/'
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
]
STATIC_ROOT = _STATIC_ROOT
# At the time of testing:
# main-full.css: 34K
# 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': [],
_storage = 'django.contrib.staticfiles.storage'
STORAGES = {
"staticfiles": {
"BACKEND": _storage + ".ManifestStaticFilesStorage",
},
}
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'sass --no-source-map {infile} {outfile}'),
)
STATIC_ROOT = _STATIC_ROOT
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>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{% block "title" %}11sync.net{% endblock %}</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
{% compress css %}
<link rel="stylesheet" type="text/x-scss" href="{% static "style.scss" %}">
{% endcompress %}
<link rel="stylesheet" type="text/css" href="{% static "style.css" %}">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>
<body id="page-{% block "pagename" %}{% endblock %}">

View File

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

View File

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

View File

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