Add env var to enable/disable thumbnail generation
This commit is contained in:
parent
7ed2ed116a
commit
2731ea9aa9
|
@ -50,5 +50,8 @@ EMAIL_HOST_PASSWORD=emailpassword123
|
||||||
EMAIL_USE_TLS=true
|
EMAIL_USE_TLS=true
|
||||||
EMAIL_USE_SSL=false
|
EMAIL_USE_SSL=false
|
||||||
|
|
||||||
|
# Thumbnails Generation
|
||||||
|
ENABLE_THUMBNAIL_GENERATION=false
|
||||||
|
|
||||||
# Set this to true when initializing certbot for domain, false when not
|
# Set this to true when initializing certbot for domain, false when not
|
||||||
CERTBOT_INIT=false
|
CERTBOT_INIT=false
|
||||||
|
|
|
@ -50,5 +50,8 @@ EMAIL_HOST_PASSWORD=emailpassword123
|
||||||
EMAIL_USE_TLS=true
|
EMAIL_USE_TLS=true
|
||||||
EMAIL_USE_SSL=false
|
EMAIL_USE_SSL=false
|
||||||
|
|
||||||
|
# Thumbnails Generation
|
||||||
|
ENABLE_THUMBNAIL_GENERATION=false
|
||||||
|
|
||||||
# Set this to true when initializing certbot for domain, false when not
|
# Set this to true when initializing certbot for domain, false when not
|
||||||
CERTBOT_INIT=false
|
CERTBOT_INIT=false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
""" customize the info available in context for rendering templates """
|
""" customize the info available in context for rendering templates """
|
||||||
from bookwyrm import models
|
from bookwyrm import models, settings
|
||||||
|
|
||||||
|
|
||||||
def site_settings(request): # pylint: disable=unused-argument
|
def site_settings(request): # pylint: disable=unused-argument
|
||||||
|
@ -7,4 +7,5 @@ def site_settings(request): # pylint: disable=unused-argument
|
||||||
return {
|
return {
|
||||||
"site": models.SiteSettings.objects.get(),
|
"site": models.SiteSettings.objects.get(),
|
||||||
"active_announcements": models.Announcement.active_announcements(),
|
"active_announcements": models.Announcement.active_announcements(),
|
||||||
|
"enable_thumbnail_generation": settings.ENABLE_THUMBNAIL_GENERATION,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ from model_utils.managers import InheritanceManager
|
||||||
from imagekit.models import ImageSpecField
|
from imagekit.models import ImageSpecField
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
from bookwyrm.settings import DOMAIN, DEFAULT_LANGUAGE
|
from bookwyrm.settings import DOMAIN, DEFAULT_LANGUAGE, ENABLE_THUMBNAIL_GENERATION
|
||||||
|
|
||||||
from .activitypub_mixin import OrderedCollectionPageMixin, ObjectMixin
|
from .activitypub_mixin import OrderedCollectionPageMixin, ObjectMixin
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
|
@ -88,20 +88,21 @@ class Book(BookDataModel):
|
||||||
|
|
||||||
objects = InheritanceManager()
|
objects = InheritanceManager()
|
||||||
|
|
||||||
cover_bw_book_xsmall_webp = ImageSpecField(source="cover", id="bw:book:xsmall:webp")
|
if ENABLE_THUMBNAIL_GENERATION:
|
||||||
cover_bw_book_xsmall_jpg = ImageSpecField(source="cover", id="bw:book:xsmall:jpg")
|
cover_bw_book_xsmall_webp = ImageSpecField(source="cover", id="bw:book:xsmall:webp")
|
||||||
cover_bw_book_small_webp = ImageSpecField(source="cover", id="bw:book:small:webp")
|
cover_bw_book_xsmall_jpg = ImageSpecField(source="cover", id="bw:book:xsmall:jpg")
|
||||||
cover_bw_book_small_jpg = ImageSpecField(source="cover", id="bw:book:small:jpg")
|
cover_bw_book_small_webp = ImageSpecField(source="cover", id="bw:book:small:webp")
|
||||||
cover_bw_book_medium_webp = ImageSpecField(source="cover", id="bw:book:medium:webp")
|
cover_bw_book_small_jpg = ImageSpecField(source="cover", id="bw:book:small:jpg")
|
||||||
cover_bw_book_medium_jpg = ImageSpecField(source="cover", id="bw:book:medium:jpg")
|
cover_bw_book_medium_webp = ImageSpecField(source="cover", id="bw:book:medium:webp")
|
||||||
cover_bw_book_large_webp = ImageSpecField(source="cover", id="bw:book:large:webp")
|
cover_bw_book_medium_jpg = ImageSpecField(source="cover", id="bw:book:medium:jpg")
|
||||||
cover_bw_book_large_jpg = ImageSpecField(source="cover", id="bw:book:large:jpg")
|
cover_bw_book_large_webp = ImageSpecField(source="cover", id="bw:book:large:webp")
|
||||||
cover_bw_book_xlarge_webp = ImageSpecField(source="cover", id="bw:book:xlarge:webp")
|
cover_bw_book_large_jpg = ImageSpecField(source="cover", id="bw:book:large:jpg")
|
||||||
cover_bw_book_xlarge_jpg = ImageSpecField(source="cover", id="bw:book:xlarge:jpg")
|
cover_bw_book_xlarge_webp = ImageSpecField(source="cover", id="bw:book:xlarge:webp")
|
||||||
cover_bw_book_xxlarge_webp = ImageSpecField(
|
cover_bw_book_xlarge_jpg = ImageSpecField(source="cover", id="bw:book:xlarge:jpg")
|
||||||
source="cover", id="bw:book:xxlarge:webp"
|
cover_bw_book_xxlarge_webp = ImageSpecField(
|
||||||
)
|
source="cover", id="bw:book:xxlarge:webp"
|
||||||
cover_bw_book_xxlarge_jpg = ImageSpecField(source="cover", id="bw:book:xxlarge:jpg")
|
)
|
||||||
|
cover_bw_book_xxlarge_jpg = ImageSpecField(source="cover", id="bw:book:xxlarge:jpg")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def author_text(self):
|
def author_text(self):
|
||||||
|
|
|
@ -187,4 +187,5 @@ USER_AGENT = "%s (BookWyrm/%s; +https://%s/)" % (
|
||||||
)
|
)
|
||||||
|
|
||||||
# Imagekit generated thumbnails
|
# Imagekit generated thumbnails
|
||||||
|
ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False)
|
||||||
IMAGEKIT_CACHEFILE_DIR = "thumbnails"
|
IMAGEKIT_CACHEFILE_DIR = "thumbnails"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load static %}
|
||||||
{% load imagekit %}
|
{% load imagekit %}
|
||||||
|
|
||||||
{% if book.cover %}
|
{% if book.cover %}
|
||||||
|
@ -14,97 +15,101 @@
|
||||||
>
|
>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
{% if size_mobile == 'xsmall' %}
|
{% if enable_thumbnail_generation %}
|
||||||
<source
|
|
||||||
media="(max-width: 768px)"
|
{% if size_mobile == 'xsmall' %}
|
||||||
type="image/webp"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_xsmall_webp.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/webp"
|
||||||
<source
|
srcset="{{ book.cover_bw_book_xsmall_webp.url }}"
|
||||||
media="(max-width: 768px)"
|
/>
|
||||||
type="image/jpg"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_xsmall_jpg.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/jpg"
|
||||||
{% elif size_mobile == 'small' %}
|
srcset="{{ book.cover_bw_book_xsmall_jpg.url }}"
|
||||||
<source
|
/>
|
||||||
media="(max-width: 768px)"
|
{% elif size_mobile == 'small' %}
|
||||||
type="image/webp"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_small_webp.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/webp"
|
||||||
<source
|
srcset="{{ book.cover_bw_book_small_webp.url }}"
|
||||||
media="(max-width: 768px)"
|
/>
|
||||||
type="image/jpg"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_small_jpg.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/jpg"
|
||||||
{% elif size_mobile == 'medium' %}
|
srcset="{{ book.cover_bw_book_small_jpg.url }}"
|
||||||
<source
|
/>
|
||||||
media="(max-width: 768px)"
|
{% elif size_mobile == 'medium' %}
|
||||||
type="image/webp"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_medium_webp.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/webp"
|
||||||
<source
|
srcset="{{ book.cover_bw_book_medium_webp.url }}"
|
||||||
media="(max-width: 768px)"
|
/>
|
||||||
type="image/jpg"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_medium_jpg.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/jpg"
|
||||||
{% elif size_mobile == 'large' %}
|
srcset="{{ book.cover_bw_book_medium_jpg.url }}"
|
||||||
<source
|
/>
|
||||||
media="(max-width: 768px)"
|
{% elif size_mobile == 'large' %}
|
||||||
type="image/webp"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_large_webp.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/webp"
|
||||||
<source
|
srcset="{{ book.cover_bw_book_large_webp.url }}"
|
||||||
media="(max-width: 768px)"
|
/>
|
||||||
type="image/jpg"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_large_jpg.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/jpg"
|
||||||
{% elif size_mobile == 'xlarge' %}
|
srcset="{{ book.cover_bw_book_large_jpg.url }}"
|
||||||
<source
|
/>
|
||||||
media="(max-width: 768px)"
|
{% elif size_mobile == 'xlarge' %}
|
||||||
type="image/webp"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_xlarge_webp.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/webp"
|
||||||
<source
|
srcset="{{ book.cover_bw_book_xlarge_webp.url }}"
|
||||||
media="(max-width: 768px)"
|
/>
|
||||||
type="image/jpg"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_xlarge_jpg.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/jpg"
|
||||||
{% elif size_mobile == 'xxlarge' %}
|
srcset="{{ book.cover_bw_book_xlarge_jpg.url }}"
|
||||||
<source
|
/>
|
||||||
media="(max-width: 768px)"
|
{% elif size_mobile == 'xxlarge' %}
|
||||||
type="image/webp"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_xxlarge_webp.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/webp"
|
||||||
<source
|
srcset="{{ book.cover_bw_book_xxlarge_webp.url }}"
|
||||||
media="(max-width: 768px)"
|
/>
|
||||||
type="image/jpg"
|
<source
|
||||||
srcset="{{ book.cover_bw_book_xxlarge_jpg.url }}"
|
media="(max-width: 768px)"
|
||||||
/>
|
type="image/jpg"
|
||||||
{% endif %}
|
srcset="{{ book.cover_bw_book_xxlarge_jpg.url }}"
|
||||||
|
/>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if size == 'xsmall' %}
|
||||||
|
<source type="image/webp" srcset="{{ book.cover_bw_book_xsmall_webp.url }}"/>
|
||||||
|
<source type="image/jpg" srcset="{{ book.cover_bw_book_xsmall_jpg.url }}"/>
|
||||||
|
{% elif size == 'small' %}
|
||||||
|
<source type="image/webp" srcset="{{ book.cover_bw_book_small_webp.url }}"/>
|
||||||
|
<source type="image/jpg" srcset="{{ book.cover_bw_book_small_jpg.url }}"/>
|
||||||
|
{% elif size == 'medium' %}
|
||||||
|
<source type="image/webp" srcset="{{ book.cover_bw_book_medium_webp.url }}"/>
|
||||||
|
<source type="image/jpg" srcset="{{ book.cover_bw_book_medium_jpg.url }}"/>
|
||||||
|
{% elif size == 'large' %}
|
||||||
|
<source type="image/webp" srcset="{{ book.cover_bw_book_large_webp.url }}"/>
|
||||||
|
<source type="image/jpg" srcset="{{ book.cover_bw_book_large_jpg.url }}"/>
|
||||||
|
{% elif size == 'xlarge' %}
|
||||||
|
<source type="image/webp" srcset="{{ book.cover_bw_book_xlarge_webp.url }}"/>
|
||||||
|
<source type="image/jpg" srcset="{{ book.cover_bw_book_xlarge_jpg.url }}"/>
|
||||||
|
{% elif size == 'xxlarge' %}
|
||||||
|
<source type="image/webp" srcset="{{ book.cover_bw_book_xxlarge_webp.url }}"/>
|
||||||
|
<source type="image/jpg" srcset="{{ book.cover_bw_book_xxlarge_jpg.url }}"/>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if size == 'xsmall' %}
|
|
||||||
<source type="image/webp" srcset="{{ book.cover_bw_book_xsmall_webp.url }}"/>
|
|
||||||
<source type="image/jpg" srcset="{{ book.cover_bw_book_xsmall_jpg.url }}"/>
|
|
||||||
{% elif size == 'small' %}
|
|
||||||
<source type="image/webp" srcset="{{ book.cover_bw_book_small_webp.url }}"/>
|
|
||||||
<source type="image/jpg" srcset="{{ book.cover_bw_book_small_jpg.url }}"/>
|
|
||||||
{% elif size == 'medium' %}
|
|
||||||
<source type="image/webp" srcset="{{ book.cover_bw_book_medium_webp.url }}"/>
|
|
||||||
<source type="image/jpg" srcset="{{ book.cover_bw_book_medium_jpg.url }}"/>
|
|
||||||
{% elif size == 'large' %}
|
|
||||||
<source type="image/webp" srcset="{{ book.cover_bw_book_large_webp.url }}"/>
|
|
||||||
<source type="image/jpg" srcset="{{ book.cover_bw_book_large_jpg.url }}"/>
|
|
||||||
{% elif size == 'xlarge' %}
|
|
||||||
<source type="image/webp" srcset="{{ book.cover_bw_book_xlarge_webp.url }}"/>
|
|
||||||
<source type="image/jpg" srcset="{{ book.cover_bw_book_xlarge_jpg.url }}"/>
|
|
||||||
{% elif size == 'xxlarge' %}
|
|
||||||
<source type="image/webp" srcset="{{ book.cover_bw_book_xxlarge_webp.url }}"/>
|
|
||||||
<source type="image/jpg" srcset="{{ book.cover_bw_book_xxlarge_jpg.url }}"/>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<img
|
<img
|
||||||
class="book-cover"
|
class="book-cover"
|
||||||
src="/images/{{ book.cover }}"
|
src="{% get_media_prefix %}{{ book.cover }}"
|
||||||
itemprop="thumbnailUrl"
|
itemprop="thumbnailUrl"
|
||||||
alt="{{ book.alt_text|default:'' }}"
|
alt="{{ book.alt_text|default:'' }}"
|
||||||
>
|
>
|
||||||
|
@ -116,7 +121,7 @@
|
||||||
<figure class="cover-container no-cover {{ cover_class }}">
|
<figure class="cover-container no-cover {{ cover_class }}">
|
||||||
<img
|
<img
|
||||||
class="book-cover"
|
class="book-cover"
|
||||||
src="/static/images/no_cover.jpg"
|
src="{% static "images/no_cover.jpg" %}"
|
||||||
alt="{% trans "No cover" %}"
|
alt="{% trans "No cover" %}"
|
||||||
>
|
>
|
||||||
<figcaption class="cover-caption">
|
<figcaption class="cover-caption">
|
||||||
|
|
Loading…
Reference in New Issue