Use the slug to identify books, not the color
authorAlex Chan <alex@alexwlchan.net>
Sat, 16 Jan 2021 11:28:10 +0000 (11:28 +0000)
committerAlex Chan <alex@alexwlchan.net>
Sat, 16 Jan 2021 11:28:10 +0000 (11:28 +0000)
Several books have the tint color black, and this was causing books with
a black cover to get the 5-star styling, even if they weren't 5-star books.

scripts/render_html.py
templates/_review_entry.html
templates/_review_style.css

index 79e2cb2..c5f96da 100755 (executable)
@@ -68,6 +68,7 @@ def set_git_timestamps():
 
 @attr.s
 class Book:
+    slug = attr.ib()
     title = attr.ib()
     author = attr.ib()
     publication_year = attr.ib()
@@ -109,6 +110,7 @@ def get_review_entry_from_path(path):
         except KeyError:
             pass
 
+    kwargs["slug"] = os.path.basename(os.path.splitext(path)[0])
     book = Book(**kwargs)
 
     review = Review(**post["review"], text=post.content)
@@ -131,7 +133,9 @@ class CurrentlyReadingEntry:
 def get_reading_entry_from_path(path):
     post = frontmatter.load(path)
 
-    book = Book(**post["book"])
+    slug = os.path.basename(os.path.splitext(path)[0])
+    book = Book(slug=slug, **post["book"])
+
     reading = CurrentlyReading(text=post.content)
 
     return CurrentlyReadingEntry(path=path, book=book, reading=reading)
@@ -160,7 +164,9 @@ class PlanEntry:
 def get_plan_entry_from_path(path):
     post = frontmatter.load(path)
 
-    book = Book(**post["book"])
+    slug = os.path.basename(os.path.splitext(path)[0])
+    book = Book(slug=slug, **post["book"])
+
     plan = Plan(date_added=post["plan"]["date_added"], text=post.content)
 
     return PlanEntry(path=path, book=book, plan=plan)
index f362b2c..b405a10 100644 (file)
@@ -7,7 +7,7 @@
 </style>
 
 <div class="review_preview {% if review_entry.review.rating == 5 and not is_index %}review_fave{% endif %}"
-id="review_preview_{{ r }}_{{ g }}_{{ b }}">
+id="review_preview_{{ review_entry.book.slug }}">
   <a href="/{{ review_entry.out_path() }}">
     <div class="book_thumbnail">
       {% set book = review_entry.book %}
index 3724cde..f0b9cc5 100644 (file)
@@ -3,7 +3,7 @@
 {% set b = (tint_colors[review_entry.book.cover_image][2] * 255) | int %}
 
 /* See https://stackoverflow.com/a/11615135/1558022 */
-#review_preview_{{ r }}_{{ g }}_{{ b }} {
+#review_preview_{{ review_entry.book.slug }} {
   border-color: rgb({{ r }}, {{ g }}, {{ b }});
 
   {% if review_entry.review.rating == 5 %}
@@ -25,7 +25,7 @@
   {% endif %}
 }
 
-#review_preview_{{ r }}_{{ g }}_{{ b }}:hover {
+#review_preview_{{ review_entry.book.slug }}:hover {
   {% if review_entry.review.rating == 5 %}
     background: rgb(
       {{ (r * 0.42 + 0.58 * 255) | int }},
@@ -41,6 +41,6 @@
   {% endif %}
 }
 
-#review_preview_{{ r }}_{{ g }}_{{ b }} a:hover {
+#review_preview_{{ review_entry.book.slug }} a:hover {
   background: none;
 }