Tidying up all the covers craziness and storages.
[wolnelektury.git] / src / wolnelektury / settings / static.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 import os
5 from .paths import VAR_DIR
6
7 # Absolute path to the directory that holds media.
8 # Example: "/home/media/media.lawrence.com/"
9 MEDIA_ROOT = os.path.join(VAR_DIR, 'media/')
10 STATIC_ROOT = os.path.join(VAR_DIR, 'static/')
11
12 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
13 # trailing slash if there is a path component (optional in other cases).
14 # Examples: "http://media.lawrence.com", "http://example.com/media/"
15 MEDIA_URL = '/media/'
16 STATIC_URL = '/static/'
17
18 IMAGE_DIR = 'book/pictures/'
19
20 # CSS and JavaScript file groups
21
22 PIPELINE = {
23     'STYLESHEETS': {
24         'main': {
25             'source_filenames': [
26                 'contrib/jquery-ui-1.13.1.custom/jquery-ui.css',
27                 'css/jquery.countdown.css',
28
29                 '2022/styles/main.scss',
30                 '2022/more.scss',
31                 'chunks/edit.scss',
32
33                 'scss/text.scss',
34                 '2022/styles/reader_player.scss',
35             ],
36             'output_filename': 'css/compressed/main.css',
37         },
38         'book_text': {
39             'source_filenames': [
40                 'css/import/gelasio.css',
41
42                 'scss/book_text.scss',
43                 'css/new.book.css',
44
45                 'annoy/banner.scss',  # ?
46                 'annoy/book_text.scss',  # ?
47                 '2022/styles/reader_player.scss',  # ?
48
49                 'css/master.picture.css',
50             ],
51             'output_filename': 'css/compressed/book_text.css',
52         },
53         'widget': {
54             'source_filenames': ('scss/widget.scss',),
55             'output_filename': 'css/compressed/widget.css',
56         },
57     },
58     'JAVASCRIPT': {
59         'main': {
60             'source_filenames': [
61                 '2022/scripts/vendor.js',
62                 'contrib/jquery-ui-1.13.1.custom/jquery-ui.js',
63                 #'js/contrib/jquery.scrollto.js',
64
65                 'js/search.js',
66                 'js/header.js',
67                 'book/filter.js',
68                 'chunks/edit.js',
69                 '2022/scripts/modernizr.js',
70                 'js/main.js',
71
72                 'js/contrib/jquery.cycle2.min.js',
73                 'sponsors/js/sponsors.js',
74                 'annoy/banner.js',
75                 'js/book_text/info.js',
76                 'js/book_text/menu.js',
77                 'js/book_text/note.js',
78                 'js/book_text/references.js',
79                 'js/book_text/settings.js',
80                 'js/book_text/toc.js',
81                 'js/book_text/progress.js',
82
83                 'js/book_text/pbox.js',
84                 'js/book_text/pbox-items.js',
85
86                 'js/contrib/jquery.countdown.js', 'js/contrib/jquery.countdown-pl.js',
87                 'js/contrib/jquery.countdown-de.js', 'js/contrib/jquery.countdown-uk.js',
88                 'js/contrib/jquery.countdown-es.js', 'js/contrib/jquery.countdown-lt.js',
89                 'js/contrib/jquery.countdown-ru.js', 'js/contrib/jquery.countdown-fr.js',
90                 'pdcounter/pdcounter.js',
91
92             ],
93             'output_filename': 'js/compressed/main.min.js'
94         },
95         'player': {
96             'source_filenames': [
97                 'js/contrib/jplayer/jquery.jplayer.min.js',
98                 'js/contrib/jplayer/jplayer.playlist.min.js',
99                 'player/player.js',
100             ],
101             'output_filename': 'js/compressed/player.min.js',
102         },
103         'book_text': {
104             'source_filenames': [
105                 'js/contrib/jquery.form.js',
106                 'js/contrib/jquery.jqmodal.js',
107
108                 'js/contrib/jquery.scrollto.js',
109
110                 'js/book_text/info.js',
111                 'js/book_text/menu.js',
112                 'js/book_text/note.js',
113                 'js/book_text/references.js',
114                 'js/book_text/settings.js',
115                 'js/book_text/toc.js',
116                 'js/locale.js',
117                 'js/dialogs.js',
118                 'annoy/book_text.js',
119
120                 'js/contrib/jquery.highlightfade.js',
121                 'js/contrib/raphael-min.js',
122                 'js/contrib/progressSpin.min.js',
123                 'annoy/banner.js',
124             ],
125             'output_filename': 'js/book_text.js',
126         },
127         'widget': {
128             'source_filenames': (
129                 'js/contrib/jquery.js',
130                 'js/contrib/jquery-ui-1.8.16.custom.min.js',
131                 'js/search.js',
132                 'js/widget_run.js',
133             ),
134             'output_filename': 'js/widget.min.js',
135         },
136     },
137     'JS_COMPRESSOR': 'pipeline.compressors.jsmin.JSMinCompressor',
138     'COMPILERS': ('pipeline.compilers.sass.SASSCompiler',),
139     'SASS_BINARY': '/opt/dart-sass/sass',
140     'SASS_ARGUMENTS': '--embed-source-map --embed-sources',
141     # Compress CSSwith a second run of dart-sass.
142     'CSS_COMPRESSOR': 'pipeline.compressors.cssmin.CSSMinCompressor',
143     'CSSMIN_BINARY': '/opt/dart-sass/sass',
144     'CSSMIN_ARGUMENTS': '--stdin --style=compressed --no-source-map',
145 }
146
147
148 STORAGES = {
149     'default': {
150         'BACKEND': 'django.core.files.storage.FileSystemStorage'
151     },
152     'book': {
153         'BACKEND': 'django.core.files.storage.FileSystemStorage',
154         'OPTIONS': {
155             'allow_overwrite': True,
156         },
157     },
158     'bookmedia': {
159         'BACKEND': 'django.core.files.storage.FileSystemStorage',
160         'OPTIONS': {
161             'allow_overwrite': True,
162         },
163     },
164     'staticfiles': {
165         'BACKEND': 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage'
166     },
167 }
168
169
170 # Switch bookmedia to s3 if set.
171 WL_BOOKMEDIA_STORAGE_MODE = os.environ.get(
172     "WL_BOOKMEDIA_STORAGE_MODE", "local") # or s3
173
174 if WL_BOOKMEDIA_STORAGE_MODE == "s3":
175     AWS_S3_REGION_NAME = os.environ.get("WL_S3_REGION", "waw")
176     AWS_S3_ENDPOINT_URL = os.environ.get(
177         "WL_S3_ENDPOINT", f"https://s3.{AWS_S3_REGION_NAME}.io.cloud.ovh.net"
178     )
179     WL_S3_BUCKET = os.environ.get("WL_S3_BUCKET")
180     STORAGES['bookmedia'] = {
181         "BACKEND": "storages.backends.s3.S3Storage",
182         "OPTIONS": {
183             "bucket_name": WL_S3_BUCKET,
184             "access_key": os.environ.get("WL_S3_ACCESS_KEY"),
185             "secret_key": os.environ.get("WL_S3_SECRET_KEY"),
186             "custom_domain": os.environ.get(
187                 "WL_S3_CUSTOM_DOMAIN",
188                 f"{WL_S3_BUCKET}.s3.{AWS_S3_REGION_NAME}.io.cloud.ovh.net"
189             ),
190             "default_acl": "public-read",
191             "querystring_auth": False,
192             "file_overwrite": True,
193         }
194     }
195
196
197
198 STATICFILES_FINDERS = [
199     'django.contrib.staticfiles.finders.FileSystemFinder',
200     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
201     'pipeline.finders.CachedFileFinder',
202     'pipeline.finders.PipelineFinder',
203 ]