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 django.db import models
from model_utils.managers import InheritanceManager from model_utils.managers import InheritanceManager
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
@ -87,6 +88,57 @@ class Book(BookDataModel):
objects = InheritanceManager() 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 @property
def author_text(self): def author_text(self):
"""format a list of authors""" """format a list of authors"""

View file

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

View file

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

View file

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