-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored for DRY avg code and conditional stats and styling
- Loading branch information
1 parent
8e3602c
commit 51edb5c
Showing
6 changed files
with
71 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,8 @@ | ||
$def with(doc) | ||
$def with(ratings_count, ratings_average, want_to_read_count) | ||
|
||
$ ratings_count = doc.get('ratings_count', None) | ||
$ ratings_average = doc.get('ratings_average', None) | ||
$ ratings_label = _('rating') if ratings_count == 1 else _('ratings') | ||
$ want_to_read_count = doc.get('want_to_read_count', None) | ||
|
||
<span class="publishedYear--ratings itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating"> | ||
<span class="ratingsByline itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating"> | ||
$if ratings_count: | ||
$ stats_decimal = (float(ratings_average))-(int(ratings_average)) | ||
$:('<span class="reader-stats__star readers-stats__star--byline">★</span>' * int(ratings_average)) | ||
$if (stats_decimal >= 0.5) and (stats_decimal < 1): | ||
$:('<span class="readers-stats__star--half reader-stats__star--byline">★</span>') | ||
<span itemprop="ratingValue">$:_('%(ratings_avg)s (%(ratings_count)s %(ratings_label)s)', ratings_avg=ratings_average, ratings_count=ratings_count, ratings_label=ratings_label)</span> | ||
<span class="dot">·</span> | ||
<span itemprop="reviewCount">$_('%(want_to_read_count)s Want to read', want_to_read_count=want_to_read_count)</span> | ||
$:macros.StarRatingsGeneral(ratings_count, ratings_average, want_to_read_count, 'results_page') | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
$def with(ratings_count, ratings_average, want_to_read_count, page_type) | ||
|
||
$ formatted_ratings_count = "{:,}".format(ratings_count) | ||
$ formatted_want_to_read_count = "{:,}".format(want_to_read_count) | ||
$ ratings_label = _('rating') if ratings_count == 1 else _('ratings') | ||
$ star_class = 'readers-stats__star' if page_type == 'book_page' else 'readers-stats__star--byline' | ||
$ half_star_class = 'readers-stats__star--half' if page_type == 'book_page' else 'readers-stats__star--byline-half' | ||
|
||
$if ratings_average: | ||
$ stats_decimal = round(float(ratings_average) - int(ratings_average), 1) | ||
$:('<span class="{}">★</span>'.format(star_class) * int(ratings_average)) | ||
$if (stats_decimal >= 0.5) and (stats_decimal < 1): | ||
$:('<span class="{}">★</span>'.format(half_star_class)) | ||
<span itemprop="ratingValue">$:_('%(ratings_avg)s (%(ratings_count)s %(ratings_label)s)', ratings_avg=ratings_average, ratings_count=formatted_ratings_count, ratings_label=ratings_label)</span> | ||
$if want_to_read_count > 0 and ratings_count > 0: | ||
<span class="dot">·</span> | ||
$if want_to_read_count > 0: | ||
<span itemprop="reviewCount">$_('%(want_to_read_count)s Want to read', want_to_read_count=formatted_want_to_read_count)</span> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters