Skip to content

Commit

Permalink
Add data
Browse files Browse the repository at this point in the history
  • Loading branch information
nntrn committed Apr 2, 2024
1 parent fa244dc commit d0402ba
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compress_html:
profile: false

page_gen:
- data: "genre"
- data: "genres"
template: "genre"
index_files: true
dir: "tag"
Expand Down
12 changes: 4 additions & 8 deletions _layouts/genre.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
layout: default
type: genre
---
{%- assign title = page.tag -%}
{%- assign pagetag = page.tag -%}
{%- assign bookpages = site.data.books | where: 'tags', pagetag -%}
{%- assign booklist = page.books | sort: "title" %}
<section>
<h2>#{{pagetag}}</h2>
<h2>#{{page.tag}}</h2>
<ul style="--gap:.25rem;width:90%">
{%- assign sortedbook = bookpages | sort: 'title' %}
{%- for book in sortedbook %}
{%- assign bookurl = book.tags | join: "/" | join: book.slug %}
{%- for book in booklist %}
<li class="lh-2">
<span><a href="{{ book.slug }}">{{book.title}}</a> by {{book.author}}</span><br>
<label class="bull small">
<span>{{book.count}} bookmarks</span>
<span>last read on <time>{{book.modified|date: '%b %Y'}}</time></span>
</label>
</li>
{% endfor %}
{%- endfor %}
</ul>
</section>
3 changes: 3 additions & 0 deletions assets/data/books.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
---
{{site.data.books|jsonify}}
3 changes: 3 additions & 0 deletions assets/data/genres.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
---
{{site.data.genres|jsonify}}
3 changes: 3 additions & 0 deletions assets/data/stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
---
{{site.data.stats.month|jsonify}}
15 changes: 13 additions & 2 deletions scripts/build-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ create_book_data() {

create_genre_data() {
_log "Creating genre.json..."
cat $ANNOTATIONS_FILE | jq -L $DIR 'include "books"; map({tag: get_tags(.ZGENRE)})| unique'
cat $OUTDIR/books.json |
jq 'group_by(.tags)|map({tag: (.[0].tags), books: (map(del(.tags))) })'
}

create_activity_data() {
Expand Down Expand Up @@ -74,6 +75,16 @@ create_stats() {
| group_by(.groupby_label)
| map({key: .[0].groupby_label, value: length})
| from_entries' >$OUTDIR/stats/bookmarks_per_month.json

cat $OUTDIR/activity.json |
jq 'map(.+{sort:(.created|fromdate|strftime("%Y-%m")),d:(.created|fromdate|strftime("%b %Y"))})
| sort_by(.sort) | group_by(.d)|sort_by(.[0].sort)
| map({(.[0].d): {
started: (map(.assetid)|unique),
saved_count: length,
saved: (group_by(.assetid)|map({(.[0].assetid): length})|add)
}
}) | add' >$OUTDIR/stats/month.json
}

while true; do
Expand All @@ -95,7 +106,7 @@ if [[ -s $ANNOTATIONS_FILE ]]; then
_log "===> Files will be saved to $OUTDIR <===" 36
mkdir -p $OUTDIR
create_book_data >$OUTDIR/books.json
create_genre_data >$OUTDIR/genre.json
create_genre_data >$OUTDIR/genres.json
create_activity_data >$OUTDIR/activity.json
create_stats
else
Expand Down

0 comments on commit d0402ba

Please sign in to comment.