This should now work

This commit is contained in:
Joachim 2021-06-06 21:12:21 +02:00
parent bbbae9fc9d
commit 1f2c296cfd
4 changed files with 158 additions and 120 deletions

View file

@ -3,6 +3,7 @@ import re
from django.db import models
from model_utils.managers import InheritanceManager
from imagekit.models import ImageSpecField
from bookwyrm import activitypub
from bookwyrm.settings import DOMAIN, DEFAULT_LANGUAGE
@ -87,6 +88,57 @@ class Book(BookDataModel):
objects = InheritanceManager()
cover_bw_book_xsmall_webp = ImageSpecField(
source='cover',
id='bw:book:xsmall:webp'
)
cover_bw_book_xsmall_jpg = ImageSpecField(
source='cover',
id='bw:book:xsmall:jpg'
)
cover_bw_book_small_webp = ImageSpecField(
source='cover',
id='bw:book:small:webp'
)
cover_bw_book_small_jpg = ImageSpecField(
source='cover',
id='bw:book:small:jpg'
)
cover_bw_book_medium_webp = ImageSpecField(
source='cover',
id='bw:book:medium:webp'
)
cover_bw_book_medium_jpg = ImageSpecField(
source='cover',
id='bw:book:medium:jpg'
)
cover_bw_book_large_webp = ImageSpecField(
source='cover',
id='bw:book:large:webp'
)
cover_bw_book_large_jpg = ImageSpecField(
source='cover',
id='bw:book:large:jpg'
)
cover_bw_book_xlarge_webp = ImageSpecField(
source='cover',
id='bw:book:xlarge:webp'
)
cover_bw_book_xlarge_jpg = ImageSpecField(
source='cover',
id='bw:book:xlarge:jpg'
)
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'
)
@property
def author_text(self):
"""format a list of authors"""

View file

@ -185,3 +185,6 @@ USER_AGENT = "%s (BookWyrm/%s; +https://%s/)" % (
VERSION,
DOMAIN,
)
# Imagekit generated thumbnails
IMAGEKIT_CACHEFILE_DIR = "thumbnails"

View file

@ -5,127 +5,110 @@
{% if book.cover %}
<picture class="cover-container {{ cover_class }}">
{% with external_path|yesno:',/images/' as image_path %}
{% if external_path %}
<img
class="book-cover"
src="{{ book.cover }}"
itemprop="thumbnailUrl"
alt="{{ book.alt_text|default:'' }}"
>
{% else %}
{% if size_mobile == 'xsmall' %}
{% generateimage 'bw:book:xsmall:webp' source=book.cover as th_xsmall_webp %}
{% generateimage 'bw:book:xsmall:jpg' source=book.cover as th_xsmall_jpg %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ image_path }}{{ th_xsmall_webp }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ image_path }}{{ th_xsmall_jpg }}"
/>
{% elif size_mobile == 'small' %}
{% generateimage 'bw:book:small:webp' source=book.cover as th_small_webp %}
{% generateimage 'bw:book:small:jpg' source=book.cover as th_small_jpg %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ image_path }}{{ th_small_webp }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ image_path }}{{ th_small_jpg }}"
/>
{% elif size_mobile == 'medium' %}
{% generateimage 'bw:book:medium:webp' source=book.cover as th_medium_webp %}
{% generateimage 'bw:book:medium:jpg' source=book.cover as th_medium_jpg %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ image_path }}{{ th_medium_webp }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ image_path }}{{ th_medium_jpg }}"
/>
{% elif size_mobile == 'large' %}
{% generateimage 'bw:book:large:webp' source=book.cover as th_large_webp %}
{% generateimage 'bw:book:large:jpg' source=book.cover as th_large_jpg %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ image_path }}{{ th_large_webp }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ image_path }}{{ th_large_jpg }}"
/>
{% elif size_mobile == 'xlarge' %}
{% generateimage 'bw:book:xlarge:webp' source=book.cover as th_xlarge_webp %}
{% generateimage 'bw:book:xlarge:jpg' source=book.cover as th_xlarge_jpg %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ image_path }}{{ th_xlarge_webp }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ image_path }}{{ th_xlarge_jpg }}"
/>
{% elif size_mobile == 'xxlarge' %}
{% generateimage 'bw:book:xxlarge:webp' source=book.cover as th_xxlarge_webp %}
{% generateimage 'bw:book:xxlarge:jpg' source=book.cover as th_xxlarge_jpg %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ image_path }}{{ th_xxlarge_webp }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ image_path }}{{ th_xxlarge_jpg }}"
/>
{% if size_mobile == 'xsmall' %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ book.cover_bw_book_xsmall_webp.url }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ book.cover_bw_book_xsmall_jpg.url }}"
/>
{% elif size_mobile == 'small' %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ book.cover_bw_book_small_webp.url }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ book.cover_bw_book_small_jpg.url }}"
/>
{% elif size_mobile == 'medium' %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ book.cover_bw_book_medium_webp.url }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ book.cover_bw_book_medium_jpg.url }}"
/>
{% elif size_mobile == 'large' %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ book.cover_bw_book_large_webp.url }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ book.cover_bw_book_large_jpg.url }}"
/>
{% elif size_mobile == 'xlarge' %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ book.cover_bw_book_xlarge_webp.url }}"
/>
<source
media="(max-width: 768px)"
type="image/jpg"
srcset="{{ book.cover_bw_book_xlarge_jpg.url }}"
/>
{% elif size_mobile == 'xxlarge' %}
<source
media="(max-width: 768px)"
type="image/webp"
srcset="{{ book.cover_bw_book_xxlarge_webp.url }}"
/>
<source
media="(max-width: 768px)"
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 %}
<img
class="book-cover"
src="/images/{{ book.cover }}"
itemprop="thumbnailUrl"
alt="{{ book.alt_text|default:'' }}"
>
{% endif %}
{% if size == 'xsmall' %}
{% generateimage 'bw:book:xsmall:webp' source=book.cover as th_xsmall_webp %}
{% generateimage 'bw:book:xsmall:jpg' source=book.cover as th_xsmall_jpg %}
<source type="image/webp" srcset="{{ image_path }}{{ th_xsmall_webp }}"/>
<source type="image/jpg" srcset="{{ image_path }}{{ th_xsmall_jpg }}"/>
{% elif size == 'small' %}
{% generateimage 'bw:book:small:webp' source=book.cover as th_small_webp %}
{% generateimage 'bw:book:small:jpg' source=book.cover as th_small_jpg %}
<source type="image/webp" srcset="{{ image_path }}{{ th_small_webp }}"/>
<source type="image/jpg" srcset="{{ image_path }}{{ th_small_jpg }}"/>
{% elif size == 'medium' %}
{% generateimage 'bw:book:medium:webp' source=book.cover as th_medium_webp %}
{% generateimage 'bw:book:medium:jpg' source=book.cover as th_medium_jpg %}
<source type="image/webp" srcset="{{ image_path }}{{ th_medium_webp }}"/>
<source type="image/jpg" srcset="{{ image_path }}{{ th_medium_jpg }}"/>
{% elif size == 'large' %}
{% generateimage 'bw:book:large:webp' source=book.cover as th_large_webp %}
{% generateimage 'bw:book:large:jpg' source=book.cover as th_large_jpg %}
<source type="image/webp" srcset="{{ image_path }}{{ th_large_webp }}"/>
<source type="image/jpg" srcset="{{ image_path }}{{ th_large_jpg }}"/>
{% elif size == 'xlarge' %}
{% generateimage 'bw:book:xlarge:webp' source=book.cover as th_xlarge_webp %}
{% generateimage 'bw:book:xlarge:jpg' source=book.cover as th_xlarge_jpg %}
<source type="image/webp" srcset="{{ image_path }}{{ th_xlarge_webp }}"/>
<source type="image/jpg" srcset="{{ image_path }}{{ th_xlarge_jpg }}"/>
{% elif size == 'xxlarge' %}
{% generateimage 'bw:book:xxlarge:webp' source=book.cover as th_xxlarge_webp %}
{% generateimage 'bw:book:xxlarge:jpg' source=book.cover as th_xxlarge_jpg %}
<source type="image/webp" srcset="{{ image_path }}{{ th_xxlarge_webp }}"/>
<source type="image/jpg" srcset="{{ image_path }}{{ th_xxlarge_jpg }}"/>
{% endif %}
<img
class="book-cover"
src="{{ image_path }}{{ book.cover }}"
itemprop="thumbnailUrl"
alt="{{ book.alt_text|default:'' }}"
>
{% endwith %}
</picture>
{% endif %}

View file

@ -5,7 +5,7 @@ django-model-utils==4.0.0
environs==7.2.0
flower==0.9.4
Markdown==3.3.3
Pillow>=7.1.0
Pillow>=8.2.0
psycopg2==2.8.4
pycryptodome==3.9.4
python-dateutil==2.8.1