-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using book cover sizes to prevent layout shifting #10145
base: master
Are you sure you want to change the base?
Changes from 10 commits
03fb650
932a6f8
ff001c3
4d9d777
f9820eb
5dce011
ed108a2
cab1bb4
b9956a4
8949f29
94b8748
54d132c
8b388aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here unfortunately, this will not be able to use/display the cover width/height until it is in solr. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cover is very rarely displayed, and fetching the cover size before rendering it is not worth the complexity and performance costs, I believe, so we can roll back the changes to this piece (and where |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,30 @@ | |
$ src = cover_url or '/images/icons/avatar_book.png' | ||
$ srcset = '%s 2x' % (cover_lg or '/images/icons/avatar_book-lg.png') | ||
|
||
$ cover_height = None | ||
$ cover_width = 180 # Fixed width of the image | ||
$ aspect_ratio = 1 | ||
$ cover = book.get_cover() | ||
$if cover: | ||
$ cover_height = cover.height() | ||
$ cover_width = cover.width() | ||
$ aspect_ratio = cover.width() / cover.height() | ||
$else: | ||
$ ia_cover_url = book.get_ia_cover(book.ocaid, "M") | ||
$ parts = ia_cover_url.split('_h') | ||
$ cover_height_str = parts[1].split('.')[0] | ||
$ cover_height = int(cover_height_str) | ||
$ cover_width_str = parts[0].split('_w')[1] | ||
$ cover_width = int(cover_width_str) | ||
$ aspect_ratio = cover_width / cover_height | ||
|
||
$ fixed_width = 180 # Fixed width of the container | ||
$ calculated_height = fixed_width / aspect_ratio | ||
|
||
$if preload: | ||
$add_metatag(tag="link", **{'rel': 'preload', 'as': 'image', 'href': src, 'imagesrcset': srcset}) | ||
|
||
<div class="coverMagic cover-animation"> | ||
<div class="coverMagic cover-animation" style="min-height: ${calculated_height}px;"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we'll only need to specify the aspect ratio; e.g. |
||
<div class="SRPCover bookCover" style="display: $cond(cover_url, 'block', 'none');"> | ||
<a | ||
href="$cover_lg" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here unfortunately, this will have to be rolled back to avoid a performance hit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have access to the database that contains all the cover info, instead of making a network request, it would be faster to instead make a database request.
I think calling the
details
method should fix this:https://github.com/internetarchive/openlibrary/blob/8b2a94044f01b9388b96ff094559c8e4637b6d4f/openlibrary/coverstore/db.py