Include a few books on the home page
authorAlex Chan <alex@alexwlchan.net>
Mon, 11 May 2020 13:44:49 +0000 (14:44 +0100)
committerAlex Chan <alex@alexwlchan.net>
Mon, 11 May 2020 13:44:49 +0000 (14:44 +0100)
scripts/render_html.py
templates/_review_entry.html [new file with mode: 0644]
templates/index.html
templates/list_reviews.html

index 7853abf..0d8ab1f 100755 (executable)
@@ -321,7 +321,10 @@ def main():
     # Render the front page
 
     index_template = env.get_template("index.html")
-    html = index_template.render(text=open("src/index.md").read())
+    html = index_template.render(
+        text=open("src/index.md").read(),
+        reviews=all_reviews[:5]
+    )
 
     index_path = pathlib.Path("_html") / "index.html"
     index_path.write_text(html)
diff --git a/templates/_review_entry.html b/templates/_review_entry.html
new file mode 100644 (file)
index 0000000..313fa67
--- /dev/null
@@ -0,0 +1,36 @@
+<div class="review_preview {% if review_entry.review.rating == 5 %}review_fave{% endif %}">
+  <a href="/{{ review_entry.out_path() }}">
+    <div class="book_thumbnail">
+      {% set book = review_entry.book %}
+      {% include "_book_cover.html" %}
+    </div>
+
+    <div class="book_metadata">
+      <p class="title">{{ review_entry.book.title | smartypants | safe }}</p>
+      <p>
+        <small>
+          by {{ review_entry.book.author }}
+          {%- if review_entry.book.publication_year %}
+            ({{ review_entry.book.publication_year}})
+          {%- endif -%}
+            <br/>
+          {% if review_entry.review.date_read %}
+          read {{ review_entry.review.date_read | render_date }}
+            <br/>
+          {% endif %}
+          {% if review_entry.review.rating %}
+            {% for _ in range(review_entry.review.rating) %}
+            ★
+            {% endfor %}
+            {% for _ in range(5 - review_entry.review.rating) %}
+            ☆
+            {% endfor %}
+          {% endif %}
+          {% if review_entry.review.did_not_finish %}
+            (did not finish)
+          {% endif %}
+        </small>
+      </p>
+    </div>
+  </a>
+</div>
index 4e9200b..c746ecf 100644 (file)
@@ -2,4 +2,12 @@
 
 {% block content %}
 {{ text | render_markdown | safe }}
+
+<p>Here are a few of the books I&rsquo;ve read recently:</p>
+
+<div class="books_by_year">
+  {% for review_entry in reviews %}
+    {% include "_review_entry.html" %}
+  {% endfor %}
+</div>
 {% endblock %}
index ffaac44..08d17eb 100644 (file)
     </h3>
 
     {% for review_entry in reviews %}
-    <div class="review_preview {% if review_entry.review.rating == 5 %}review_fave{% endif %}">
-      <a href="/{{ review_entry.out_path() }}">
-        <div class="book_thumbnail">
-          {% set book = review_entry.book %}
-          {% include "_book_cover.html" %}
-        </div>
-
-        <div class="book_metadata">
-          <p class="title">{{ review_entry.book.title | smartypants | safe }}</p>
-          <p>
-            <small>
-              by {{ review_entry.book.author }}
-              {%- if review_entry.book.publication_year %}
-                ({{ review_entry.book.publication_year}})
-              {%- endif -%}
-                <br/>
-              {% if review_entry.review.date_read %}
-              read {{ review_entry.review.date_read | render_date }}
-                <br/>
-              {% endif %}
-              {% if review_entry.review.rating %}
-                {% for _ in range(review_entry.review.rating) %}
-                ★
-                {% endfor %}
-                {% for _ in range(5 - review_entry.review.rating) %}
-                ☆
-                {% endfor %}
-              {% endif %}
-              {% if review_entry.review.did_not_finish %}
-                (did not finish)
-              {% endif %}
-            </small>
-          </p>
-        </div>
-      </a>
-    </div>
+      {% include "_review_entry.html" %}
     {% endfor %}
   </div>