Skip to content

Instantly share code, notes, and snippets.

@mekarpeles
Created September 15, 2024 19:29
Show Gist options
  • Save mekarpeles/3545a49c914b78aeaa7be4e9ec16f9cd to your computer and use it in GitHub Desktop.
Save mekarpeles/3545a49c914b78aeaa7be4e9ec16f9cd to your computer and use it in GitHub Desktop.
diff --git a/openlibrary/macros/SearchResultsWork.html b/openlibrary/macros/SearchResultsWork.html
index dcb90ee3d..1dd35351d 100644
--- a/openlibrary/macros/SearchResultsWork.html
+++ b/openlibrary/macros/SearchResultsWork.html
@@ -113,9 +113,10 @@ $code:
<span>
<a href="$work_edition_all_url#editions-list">$ungettext('%(count)s edition', '%(count)s editions', doc.edition_count, count=doc.edition_count)</a>
</span>
- $if doc.get('languages'):
+ $if doc.get('languages') and doc_type in ['infogami_work', 'solr_work']:
<span class="languages">
- $:ungettext('in <a class="hoverlink" title="%(langs)s">%(count)d language</a>', 'in <a class="hoverlink" title="%(langs)s">%(count)d languages</a>', len(doc.languages), count=len(doc.languages), langs=commify_list([get_language_name('/languages/' + lang) for lang in doc.languages]))
+ $ langs = [get_language_name(lang.key if hasattr(lang, 'key') else '/languages' + lang) for lang in doc.languages]
+ $:ungettext('in <a class="hoverlink" title="%(langs)s">%(count)d language</a>', 'in <a class="hoverlink" title="%(langs)s">%(count)d languages</a>', len(doc.languages), count=len(doc.languages), langs=commify_list(langs))
</span>
</span>
</span>
diff --git a/openlibrary/macros/StarRatingsComponent.html b/openlibrary/macros/StarRatingsComponent.html
index 10f2a36b6..abc5bea3c 100644
--- a/openlibrary/macros/StarRatingsComponent.html
+++ b/openlibrary/macros/StarRatingsComponent.html
@@ -3,12 +3,11 @@ $def with(ratings_count, ratings_average, page_type)
$ rounded_avg = "%.1f" % ratings_average
$ formatted_ratings_count = "{:,}".format(ratings_count) if ratings_count else ""
$ 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'
+$ small = "star--small" if page_type != 'book_page' else ''
$if ratings_average:
$ stats_decimal = (float(ratings_average) - int(ratings_average))
- $:('<span class="{}">★</span>'.format(star_class) * int(ratings_average))
+ $:('<span class="star {}">★</span>'.format(small) * int(ratings_average))
$if (stats_decimal >= 0.5) and (stats_decimal < 1):
- $:('<span class="{}">★</span>'.format(half_star_class))
+ <span class="star star--half $small">★</span>
<span itemprop="ratingValue">$:_('%(ratings_avg)s (%(ratings_count)s %(ratings_label)s)', ratings_avg=rounded_avg, ratings_count=formatted_ratings_count, ratings_label=ratings_label)</span>
diff --git a/openlibrary/macros/StarRatingsStats.html b/openlibrary/macros/StarRatingsStats.html
index a4d1ac594..1c927869b 100644
--- a/openlibrary/macros/StarRatingsStats.html
+++ b/openlibrary/macros/StarRatingsStats.html
@@ -2,27 +2,24 @@ $def with(work, mobile=False)
$ rating_stats = work and work.get_rating_stats() or {}
$ stats_by_bookshelf = work and work.get_num_users_by_bookshelf() or {}
-$ avg = rating_stats.get('avg_rating')
+$ ratings_average = rating_stats.get('avg_rating')
$ ratings_count = rating_stats.get('num_ratings', 0)
$ want_to_read_count = "{:,}".format(stats_by_bookshelf.get('want-to-read', 0))
$ currently_reading_count = "{:,}".format(stats_by_bookshelf.get('currently-reading', 0))
$ already_read_count = "{:,}".format(stats_by_bookshelf.get('already-read', 0))
+$ review_count_class = 'readers-stats__review-count--none' if ratings_count == 0 else ''
$ id = '--mobile' if mobile else ''
<ul class="readers-stats $review_count_class" itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">
<li class="avg-ratings" onclick="location.href='#starRatingSection';" data-ol-link-track="StarRating|StatsComponentClick">
- $if avg:
- $ stats_decimal = (float(avg))-(int(avg))
- $:('<span class="readers-stats__star">★</span>' * int(avg))
- $if (stats_decimal >= 0.5) and (stats_decimal < 1):
- $:('<span class="readers-stats__star--half">★</span>')
- <span itemprop="ratingValue">$avg</span>
+ $if ratings_count:
+ $:macros.StarRatingsComponent(ratings_count, ratings_average, 'results_page')
<span class="dot">·</span>
</li>
- $if want_to_read_count > 0:
+ $if want_to_read_count:
<li class="reading-log-stat"><span class="readers-stats__stat">$want_to_read_count</span> <span class="readers-stats__label">$_("Want to read")</span></li>
- $if currently_reading_count > 0:
+ $if currently_reading_count:
<li class="reading-log-stat"><span class="readers-stats__stat">$currently_reading_count</span> <span class="readers-stats__label">$_("Currently reading")</span></li>
- $if already_read_count > 0:
+ $if already_read_count:
<li class="reading-log-stat"><span class="readers-stats__stat">$already_read_count</span> <span class="readers-stats__label">$_("Have read")</span></li>
</ul>
diff --git a/static/css/components/readerStats.less b/static/css/components/readerStats.less
index 348af6aaa..c0140f771 100644
--- a/static/css/components/readerStats.less
+++ b/static/css/components/readerStats.less
@@ -3,6 +3,21 @@
* https://github.com/internetarchive/openlibrary/wiki/Design-Pattern-Library#readerstats
*/
+.star {
+ color: @gold;
+ font-size: 1.5em;
+ &__small {
+ font-size: 1em;
+ }
+ &--half {
+ color: @gold;
+ margin: 0 0 0 -5px;
+ background: linear-gradient(90deg, @gold 50%, @light-grey 50%);
+ -webkit-background-clip: text;
+ -webkit-text-fill-color: transparent;
+ }
+}
+
.readers-stats {
color: @grey;
font-size: @font-size-label-large;
@@ -12,7 +27,7 @@
display: inline-block;
padding-bottom: 10px;
- &:not(:last-child):after {
+ &:not(:first-child,:last-child):after {
content: "·";
margin: 0 4px;
}
@@ -22,24 +37,4 @@
display: inline-block;
margin: 0 4px;
}
-
- &__star {
- color: @gold;
- font-size: 1.5em;
- }
- &__star--half {
- color: @gold;
- margin: 0 0 0 -5px;
- background: linear-gradient(90deg, @gold 50%, @light-grey 50%);
- -webkit-background-clip: text;
- -webkit-text-fill-color: transparent;
- }
- &__star--byline {
- color: @gold;
- font-size: 1em;
- }
- &__star--byline-half {
- color: @gold;
- font-size: 1em;
- }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment