-
-
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?
Conversation
Can you provide some screenshots so we can visually inspect the before/after? Thank you! EDIT: I now see the videos! Disregard :) Also, it seems like the commit history may need a bit of a rebase / cleanup. @RayBB do you mind taking a first look? |
…te of lists Remove docs for calculating cover image dimensions in home template
…adjust image height to covers in already-lists
fix trailing spaces Remove unnecessary blank lines in initMyBooksAffordances function
A new container is added and the size of the covers is standardized A new container is added and the size of the covers is standardized
…static/css/components/search-result-item.less file. applied black formatter
Hello @mekarpeles Regarding the commit history, we just done a rebase and cleanup. Feel free to reach out if you have any other questions or need additional information! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #10145 +/- ##
==========================================
+ Coverage 17.12% 17.42% +0.29%
==========================================
Files 89 89
Lines 4752 4799 +47
Branches 831 848 +17
==========================================
+ Hits 814 836 +22
- Misses 3428 3443 +15
- Partials 510 520 +10 ☔ View full report in Codecov by Sentry. |
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.
Hey folks this is a great start!
I left a few small notes on the PR itself.
However, you also seem to have created a regression on the search results page.
Please fix that and the other comments and then I'll try to take a closer look.
Good luck!
static/css/layout/index.less
Outdated
@@ -13,7 +13,7 @@ div.contentBody, | |||
div#contentBody { | |||
padding: 0 @contentBody-padding @contentBody-padding; | |||
img { | |||
max-width: 100%; | |||
// max-width: 100%; |
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.
If you want this to be removed please delete it completely instead of commenting it out.
@@ -84,14 +84,12 @@ | |||
filter: blur(2px); | |||
} | |||
} | |||
.bookcover { | |||
width: 100%; | |||
.git { |
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.
Is this an intentional change? Probably a typo
static/css/components/listLists.less
Outdated
width: 32px; | ||
max-width: 100%; | ||
width: 22px; | ||
// max-width: 100%; |
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.
Again, if you want this to be deleted please fully delete it.
|
||
|
||
<style scoped> |
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.
Please try to keep the changeset small by avoiding whitespace changes like this one.
…ass, Removed unnecessary whitespace changes and Fixed regression issue on search results page Also, added a function to retrieve dimensions of a cover by its URL docs: add docstring to get_dimensions_cover function added newline at end of file in search-result-item.less format imports and clean up whitespace in book_providers.py
Hi @RayBB Thank you for your feedback! I've addressed the comments and made the necessary changes:
|
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.
I've taken one more brief look and found two issues:
-
The cover in the search results has the wrong aspect ratio and as such is distorted.
-
The aspect ratio is also causing distortion in the "more by this author" section
Please fix the two above issues.
Also, please edit your original PR testing instructions to include a complete list of (localhost) URLs where we should see the changes.
As for the code itself, I didn't look closely as @cdrini is the lead and will likely have detailed feedback on that when he reviews it.
Overall, good work on this. It's certainly not an easy task to get this working in so many places.
…s related to covers in the search results
…e book.less Removed unnecessary changes in custom_carousel.html restored changes in custom_carousel.html
Hi @RayBB, I've resolved the distortion issue with the covers. It was related to the object-fit property setted as "cover", and I've made the necessary adjustments. |
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.
Hi @anna-ayn , awesome work on this one! Unfortunately looking into it some more, we only really want to affect the book page, eg book_cover.html
. Fetching the info for the cover width/height has a cost associated with it, so we don't want to be doing too frequently. On the book page, we only have the one main cover which causes the biggest layout shift, that's the one we want to address. The other pages, eg. search, carousels, won't be able to use the currently flow to get the width/height, because it would be too expensive to fetch that info for all those covers. There is a separate project for including this info in our solr search index which will make that possible, but for I'm afraid it's not.
Apologies for the run around here! We didn't realize the cost of this when creating the issue.
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.
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 ShowcaseItem
is called).
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.
This won't quite work, since it's hard-coding the aspect ratio to 180 / 360, but getting the image sizes for all the covers that will appear in a carousel is likely going to be expensive. I don't think that will be worth the trouble, so let's roll back this page here.
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.
Ditto with this one, the editions table displays quite a few edition covers, and would be expensive to fetch the sizing info for all of them, so leaving this as it was is best. There is a separate project to include width/height in our search index solr; once that is complete, then we can use the information there to do this kind of work!
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.
Ditto here unfortunately, this will not be able to use/display the cover width/height until it is in solr.
$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 comment
The 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. style="aspect-ratio: $cover_width / $cover_height;"
on the <img>
element. @RayBB and I tested this, and it removed the layout shift! That should simplify this up quite a bit!
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.
Ditto here unfortunately, this will have to be rolled back to avoid a performance hit.
@@ -577,6 +581,24 @@ def get_cover_url(ed_or_solr: Edition | dict) -> str | None: | |||
return None | |||
|
|||
|
|||
def get_dimensions_cover(url: str) -> tuple[int, int] | None: |
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:
Closes #9739
feature
Technical
Improvements to cover image handling:
openlibrary/book_providers.py
: Added theget_dimensions_cover
function to retrieve the dimensions of cover images from a given URL.openlibrary/core/models.py
: Addedwidth
andheight
methods to theImage
class to get the dimensions of an image.Updates to CSS styles:
openlibrary/components/LibraryExplorer/components/OLCarousel.vue
: Added styles for the.cover-container
class to handle different screen sizes and ensure images fit properly.static/css/components/book.less
: Changedimg.bookcover
to usefilter: drop-shadow
instead ofbox-shadow
and ensured the width is set to 100%.static/css/components/listLists.less
: Adjusted the width of images in lists to 22px.Template modifications:
openlibrary/macros/SearchResultsWork.html
: Incorporated theget_dimensions_cover
function to dynamically set the aspect ratio and size of cover images.openlibrary/templates/books/custom_carousel.html
: Apply the aspect ratio for book covers in the carousel.openlibrary/templates/covers/book_cover.html
: Added logic to calculate the height based on the aspect ratio and fixed width for book covers.openlibrary/templates/lists/home.html
: Added logic to calculate the height based on the aspect ratio and fixed width for book covers in the section of Active Lists.openlibrary/templates/books/edition-sort.html
: Apply the aspect ratio for book covers in Edition table.Testing
_get_active_lists_in_random(limit=20, preload=True)
as follows:This is to show all the lists in the "Active Lists" section if you have few lists in your database.
Screenshot
We have make videos demonstrating the changes and comparing with the real website of OpenLibrary;
https://drive.google.com/file/d/1RrzodyWAFDAS--mk5Y222Hjk95FYgMla/view?usp=sharing
https://drive.google.com/file/d/1BF7YWPcys6Ny2EuJ9ahkiIexsC1JjmCH/view?usp=sharing
https://drive.google.com/file/d/1UU0nRT32Oa0Bu_27FD6cN8tQES-QUqpQ/view?usp=sharing
https://drive.google.com/file/d/1qe68bcZtBNh2cbOEbi93z4s2u9XHgDtD/view?usp=sharing
https://drive.google.com/file/d/1rOheT5PNJi6iveGhcGpb589YsG9uEqXb/view?usp=drive_link
Stakeholders
@cdrini