Repository navigation
Expand file tree
/
Copy pathreading.haml
More file actions
103 lines (95 loc) · 3.91 KB
/
Copy pathreading.haml
File metadata and controls
103 lines (95 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
- require 'active_support/all'
- yearly_goals = { 2022 => 30, 2021 => 40, 2020 => 35, 2019 => 40, 2018 => 40, 2017 => 40, 2016 => 50, 2015 => 50, 2014 => 50, 2013 => 50, 2012 => 50 }
- readings = JSON.parse(File.read("reading/books.json"))
!!!
%html
{% haml header.haml %}
%body.reading
{% haml nav.haml %}
%section.section
.container
%h2.title.is-1 Reading
%p.content
The books I'm reading now and have read over the years.
%a{href: "/articles/2020/02/17/building-a-custom-reading-list-with-airtable/"} How does this work?
%h2.title.is-3 Currently Reading
.currently-reading
%ul
- readings["currently_reading"].each do |reading|
%li
%p
%strong= reading["Book"]["Title"]
by
= reading["Book"]["Authors"]
%p.started-on
Started
%span.time-ago= Date.parse(reading["Started On"]).strftime("%B %d, %Y")
- readings["by_year"].each do |year, data|
%h2.title.is-3=year
.columns
.column
.box.stats-box.has-text-centered
%h3.title.is-5 Read
- goal = yearly_goals[year.to_i]
- read = data["readings"].count
.title.read-count.is-1= read
= "book".pluralize(read)
- if year.to_i == Date.current.year
= " so far"
- else
= " total"
- if goal.present?
of a #{goal} book goal.
- if year.to_i == Date.current.year
%span#progress-to-date{data: {goal: goal, read: read}}
- if goal > read
%progress.progress.is-small{value: read, max: goal}
- data["stats"].each do |key, counts|
.column
.box.stats-box
%h3.has-text-centered.title.is-5=key
%table.table.is-fullwidth
%tbody
- counts.sort_by {|field, count| -count }.each do |field, count|
%tr
%td=field
%td=count
%table.table.is-fullwidth
%thead
%tr
%th Month
%th Book
%th Rating
%tbody
- months = data["readings"].group_by {|r| Date.parse(r["Finished On"]).month }.to_a.sort
- months.each_with_index do |pair, month_index|
- month, month_readings = pair
- month_readings.sort {|a, b| a["Finished On"] <=> b["Finished On"] }.each_with_index do |reading, i|
%tr
- if i == 0
%td{rowspan: month_readings.length, class: month_index + 1 == months.length ? "last-month-in-year" : ""}=Date::MONTHNAMES[month]
%td
%strong=reading["Book"]["Title"]
by
=reading["Book"]["Authors"]
%td
- if reading["Rating"]
= reading["Rating"].times.map{ "\u2605"}.join
- else
%span.not-rated Not Rated
-if readings["did_not_finish_by_year"][year].present?
%table.table.is-fullwidth
%thead
%tr
%th Did Not Finish
%th Month
%tbody
- readings["did_not_finish_by_year"][year]&.each do |reading|
%tr
%td
%strong=reading["Book"]["Title"]
by
=reading["Book"]["Authors"]
%td
= Date::MONTHNAMES[Date.parse(reading["Stopped Reading On"]).month]
{% include goatcounter.html %}