And now I can render a "books I want to read" page
authorAlex Chan <alex@alexwlchan.net>
Sun, 2 Feb 2020 19:49:49 +0000 (19:49 +0000)
committerAlex Chan <alex@alexwlchan.net>
Sun, 2 Feb 2020 19:49:49 +0000 (19:49 +0000)
scripts/render_html.py
src/index.md
src/plans/clouds-cannot-cover-us.md
templates/list_plans.html [new file with mode: 0644]
templates/list_reading.html
templates/list_reviews.html

index bb0eb11..fc198d8 100755 (executable)
@@ -81,7 +81,31 @@ def get_reading_entry_from_path(path):
     return CurrentlyReadingEntry(path=path, book=book, reading=reading)
 
 
     return CurrentlyReadingEntry(path=path, book=book, reading=reading)
 
 
-def get_reviews(dirpath, constructor):
+@attr.s
+class Plan:
+    text = attr.ib()
+
+
+@attr.s
+class PlanEntry:
+    path = attr.ib()
+    book = attr.ib()
+    plan = attr.ib()
+
+    def out_path(self):
+        return self.path.relative_to("src").with_suffix("")
+
+
+def get_plan_entry_from_path(path):
+    post = frontmatter.load(path)
+
+    book = Book(**post["book"])
+    plan = Plan(text=post.content)
+
+    return PlanEntry(path=path, book=book, plan=plan)
+
+
+def get_entries(dirpath, constructor):
     for dirpath, _, filenames in os.walk(dirpath):
         for f in filenames:
             if not f.endswith(".md"):
     for dirpath, _, filenames in os.walk(dirpath):
         for f in filenames:
             if not f.endswith(".md"):
@@ -146,7 +170,7 @@ if __name__ == "__main__":
     # Render the "all reviews page"
 
     all_reviews = list(
     # Render the "all reviews page"
 
     all_reviews = list(
-        get_reviews(dirpath="src/reviews", constructor=get_review_entry_from_path)
+        get_entries(dirpath="src/reviews", constructor=get_review_entry_from_path)
     )
     all_reviews = sorted(
         all_reviews, key=lambda rev: str(rev.review.date_read), reverse=True
     )
     all_reviews = sorted(
         all_reviews, key=lambda rev: str(rev.review.date_read), reverse=True
@@ -164,7 +188,7 @@ if __name__ == "__main__":
     # Render the "currently reading" page
 
     all_reading = list(
     # Render the "currently reading" page
 
     all_reading = list(
-        get_reviews(dirpath="src/currently_reading", constructor=get_reading_entry_from_path)
+        get_entries(dirpath="src/currently_reading", constructor=get_reading_entry_from_path)
     )
 
     template = env.get_template("list_reading.html")
     )
 
     template = env.get_template("list_reading.html")
@@ -174,6 +198,19 @@ if __name__ == "__main__":
     out_path.parent.mkdir(exist_ok=True, parents=True)
     out_path.write_text(html)
 
     out_path.parent.mkdir(exist_ok=True, parents=True)
     out_path.write_text(html)
 
+    # Render the "want to read" page
+
+    all_plans = list(
+        get_entries(dirpath="src/plans", constructor=get_plan_entry_from_path)
+    )
+
+    template = env.get_template("list_plans.html")
+    html = template.render(all_plans=all_plans)
+
+    out_path = pathlib.Path("_html") / "to-read/index.html"
+    out_path.parent.mkdir(exist_ok=True, parents=True)
+    out_path.write_text(html)
+
     # Render the front page
 
     index_template = env.get_template("index.html")
     # Render the front page
 
     index_template = env.get_template("index.html")
index 4c7636f..3cb95db 100644 (file)
@@ -4,6 +4,6 @@ This is a small app I created to track the books I’m reading. In this app, I c
 
 *   Write mini-reviews of the [books I’ve read](/reviews/)
 *   Keep track of what I’m [currently reading](/reading/)
 
 *   Write mini-reviews of the [books I’ve read](/reviews/)
 *   Keep track of what I’m [currently reading](/reading/)
-*   Write down what books [I want to read](/plans/), and why I want to read them
+*   Write down what books [I want to read](/to-read/), and why I want to read them
 
 This was inspired by a [similar book tracker](http://tessa-books.glitch.me/) created by [Tessa Thornton](https://twitter.com/tessthornton).
 
 This was inspired by a [similar book tracker](http://tessa-books.glitch.me/) created by [Tessa Thornton](https://twitter.com/tessthornton).
index 5d6d16a..bf0f44e 100644 (file)
@@ -6,3 +6,5 @@ book:
   publication_year: '2019'
   title: Clouds Cannot Cover Us
 ---
   publication_year: '2019'
   title: Clouds Cannot Cover Us
 ---
+
+Of course I want to read Jay's poetry!
diff --git a/templates/list_plans.html b/templates/list_plans.html
new file mode 100644 (file)
index 0000000..3a695f9
--- /dev/null
@@ -0,0 +1,39 @@
+{% extends "base.html" %}
+
+{% block content %}
+  <p class="nav">
+    <a href="/reviews">read</a> /
+    <a href="/reading">reading</a> /
+    <a class="selected" href="/to-read">to read</a>
+  </p>
+
+  <h2>books i want to read</h2>
+
+  {% for plan_entry in all_plans %}
+  <div class="reading">
+    <div class="reading_inner">
+      <div class="book_thumbnail">
+        {% set book = plan_entry.book %}
+        {% include "_book_cover.html" %}
+      </div>
+
+      <div class="book_metadata">
+        <p class="title">{{ plan_entry.book.title }}</p>
+        <p>
+          <small>
+            by {{ plan_entry.book.author }}
+            {%- if plan_entry.book.publication_year %}
+              ({{ plan_entry.book.publication_year}})
+            {%- endif -%}
+          </small>
+        </p>
+      </div>
+    </div>
+    {% if plan_entry.plan.text %}
+    <div class="note">
+      {{ plan_entry.plan.text | render_markdown | safe }}
+    </div>
+    {% endif %}
+  </div>
+  {% endfor %}
+{% endblock %}
\ No newline at end of file
index ba77e50..6f8baf6 100644 (file)
@@ -4,7 +4,7 @@
   <p class="nav">
     <a href="/reviews">read</a> /
     <a class="selected" href="/reading">reading</a> /
   <p class="nav">
     <a href="/reviews">read</a> /
     <a class="selected" href="/reading">reading</a> /
-    <a href="/plans">to read</a>
+    <a href="/to-read">to read</a>
   </p>
 
   <h2>books i&rsquo;m currently reading</h2>
   </p>
 
   <h2>books i&rsquo;m currently reading</h2>
index df27833..c8eeaab 100644 (file)
@@ -4,7 +4,7 @@
   <p class="nav">
     <a class="selected" href="/reviews">read</a> /
     <a href="/reading">reading</a> /
   <p class="nav">
     <a class="selected" href="/reviews">read</a> /
     <a href="/reading">reading</a> /
-    <a href="/plans">to read</a>
+    <a href="/to-read">to read</a>
   </p>
 
   <h2>books i&rsquo;ve read</h2>
   </p>
 
   <h2>books i&rsquo;ve read</h2>