From e248cb91465bd7704d1ba4293ba3ba72aa8a79bf Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Tue, 27 Jun 2023 20:59:11 +1000 Subject: [PATCH] Bookshelf --- Rakefile | 33 ++++++++++++------------- app/assets/index.css | 8 ++++++ app/content/pages/colophon.md | 4 +-- app/decorators/books/decorator.rb | 15 ++++++++++++ app/repos/post_repo.rb | 2 +- app/templates/books/index.html.slim | 34 ++++++++++++++++++++------ app/templates/more/index.html.slim | 1 + app/templates/movies/index.html.slim | 2 +- app/templates/podcasts/index.html.slim | 2 +- app/templates/trips/index.html.slim | 2 +- app/templates/workouts/index.html.slim | 2 +- app/views/books/index.rb | 20 +++++++++++++-- config/routes.rb | 2 +- tailwind.config.js | 2 +- 14 files changed, 91 insertions(+), 38 deletions(-) diff --git a/Rakefile b/Rakefile index 7b4af17..6bd165e 100644 --- a/Rakefile +++ b/Rakefile @@ -30,27 +30,24 @@ namespace :blog do end end - task load_from_overcast: ["blog:load_environment"] do - require "nokogiri" + task load_from_bookshelf: ["blog:load_environment"] do require "hanami/prepare" - require "down" + require "csv" + require "sequel" - podcast_repo = Adamantium::Container["repos.podcast_repo"] - settings = Adamantium::Container["settings"] + post_repo = Adamantium::Container["repos.post_repo"] - podcast_repo.delete_all - - doc = File.open("tmp/overcast.opml") { |f| Nokogiri::XML(f) } - doc.xpath("//outline[@type='rss']").each do |outline| - overcast_id = outline.get_attribute("overcastId") - url = "https://public.overcast-cdn.com/art/#{overcast_id}_thumb" - destination = File.join("public", "media", "podcast_art", "#{overcast_id}.jpg") - Down.download(url, destination: destination) - - podcast_repo.create( - name: outline.get_attribute("title"), - url: outline.get_attribute("htmlUrl"), - overcast_id: outline.get_attribute("overcastId") + CSV.open("tmp/books.csv", headers: true).each do |book| + next if book["isbn13"].nil? + post_repo.create( + name: book["title"], + post_type: "book", + book_status: book["readingStatus"], + slug: "isbn:#{book["isbn13"]}", + book_author: book["authors"], + content: book["description"], + category: [], + published_at: Time.now ) end end diff --git a/app/assets/index.css b/app/assets/index.css index 2232517..f8cd060 100644 --- a/app/assets/index.css +++ b/app/assets/index.css @@ -46,3 +46,11 @@ h1, h2, h3, h4, h5, h6, h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { font-family: "JetBrainsMono", Monaco, monospace; } +.map-marker { + border: 3px solid blue; + border-radius: 8px; + background: RGBa(0, 0, 255, 0.1); + width: 14px; + height: 14px; +} + diff --git a/app/content/pages/colophon.md b/app/content/pages/colophon.md index 6d7b8cf..3652de1 100644 --- a/app/content/pages/colophon.md +++ b/app/content/pages/colophon.md @@ -1,9 +1,7 @@ -# Colophon +# 🧱 Colophon Hello! Welcome to dnitza.com 👋 - - This site is made from: - Adamantium — A custom-built, [Hanami](https://github.com/hanami/hanami)-based, blogging engine [based on the Micropub spec](https://www.w3.org/TR/micropub/) (open sourced soon). diff --git a/app/decorators/books/decorator.rb b/app/decorators/books/decorator.rb index f296fa9..e122c4f 100644 --- a/app/decorators/books/decorator.rb +++ b/app/decorators/books/decorator.rb @@ -21,6 +21,21 @@ module Adamantium def template_type :book end + + def authors + self.book_author.split(";").join(" ") + end + + def status_colour + case book_status + when "read" + "text-green-100 bg-green-500" + when "to-read" + "text-blue-100 bg-blue-500" + when "reading" + "text-orange-100 bg-orange-500" + end + end end end end diff --git a/app/repos/post_repo.rb b/app/repos/post_repo.rb index 4597470..23196a2 100644 --- a/app/repos/post_repo.rb +++ b/app/repos/post_repo.rb @@ -131,7 +131,7 @@ module Adamantium posts .where(post_type: "book") .published - .order(Sequel.desc(:published_at)) + .order(Sequel.asc(:name)) .limit(limit) .to_a end diff --git a/app/templates/books/index.html.slim b/app/templates/books/index.html.slim index 13fff0b..855e56b 100644 --- a/app/templates/books/index.html.slim +++ b/app/templates/books/index.html.slim @@ -1,23 +1,41 @@ - context.content_for(:title, "Books | ") div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200" - h1 Books + h1 📚 Bookshelf div class="mb-12 max-w-prose mx-auto" table class="prose dark:prose-invert table-auto" thead tr - td Title - td Author - td Status - - books.each do |book| + td + td class="p-2" Title + td class="p-2" Author(s) + - reading.each do |book| tr td - / a href="/books/#{book.slug}" + span class="rounded-md text-xs #{book.status_colour} p-1" + = book.book_status + td = book.name td - = book.book_author + = book.authors + - to_read.each do |book| + tr td - = book.book_status + span class="rounded-md text-xs #{book.status_colour} p-1" + = book.book_status + td + = book.name + td + = book.authors + - read.each do |book| + tr + td + span class="rounded-md text-xs #{book.status_colour} p-1" + = book.book_status + td + = book.name + td + = book.authors div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600" diff --git a/app/templates/more/index.html.slim b/app/templates/more/index.html.slim index f8f62a2..76ab133 100644 --- a/app/templates/more/index.html.slim +++ b/app/templates/more/index.html.slim @@ -17,5 +17,6 @@ div class="mb-12 max-w-prose mx-auto text-gray-800 dark:text-gray-200" a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/movies" 🍿 Movies a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/trips" 🛫 Trips a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/podcasts" 🎙️ Podcasts + a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/bookshelf" 📚️ Bookshelf / a class="block p-1 border border-blue-200 bg-blue-300 text-blue-900 hover:bg-blue-200 text-center rounded-lg" href="/art" 🎨 Art things diff --git a/app/templates/movies/index.html.slim b/app/templates/movies/index.html.slim index dd5a2b5..372076e 100644 --- a/app/templates/movies/index.html.slim +++ b/app/templates/movies/index.html.slim @@ -1,7 +1,7 @@ - context.content_for(:title, "Movies | ") div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200" - h1 Movies + h1 🍿 Movies div class="mb-12 max-w-prose mx-auto" table class="prose dark:prose-invert table-auto" diff --git a/app/templates/podcasts/index.html.slim b/app/templates/podcasts/index.html.slim index 9d7285c..27c9b3d 100644 --- a/app/templates/podcasts/index.html.slim +++ b/app/templates/podcasts/index.html.slim @@ -1,7 +1,7 @@ - context.content_for(:title, "Podcasts | ") div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200" - h1 Podcasts + h1 🎙️ Podcasts div class="mb-12 max-w-prose mx-auto" table class="prose dark:prose-invert table-auto" diff --git a/app/templates/trips/index.html.slim b/app/templates/trips/index.html.slim index e2831d8..3bee3d5 100644 --- a/app/templates/trips/index.html.slim +++ b/app/templates/trips/index.html.slim @@ -1,7 +1,7 @@ - context.content_for(:title, "Trips | ") div class="mb-4 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200" - h1 Trips + h1 🛫 Trips div class="mb-12 max-w-prose mx-auto" table class="prose dark:prose-invert table-auto" diff --git a/app/templates/workouts/index.html.slim b/app/templates/workouts/index.html.slim index b9846a5..1175194 100644 --- a/app/templates/workouts/index.html.slim +++ b/app/templates/workouts/index.html.slim @@ -1,7 +1,7 @@ - context.content_for(:title, "Hikes | ") div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200" - h1 Hikes + h1 🥾 Hikes div class="prose dark:prose-invert max-w-prose mx-auto" - workouts_by_year.each do |year, workouts| diff --git a/app/views/books/index.rb b/app/views/books/index.rb index 7a6f490..a05edb8 100644 --- a/app/views/books/index.rb +++ b/app/views/books/index.rb @@ -4,8 +4,24 @@ module Adamantium class Index < Adamantium::View include Deps["repos.post_repo"] - expose :books do - post_repo.books_listing.map do |book| + private_expose :books do + post_repo.books_listing.group_by { |book| book.book_status } + end + + expose :read do |books| + books["read"].map do |book| + Decorators::Books::Decorator.new book + end + end + + expose :to_read do |books| + books["to-read"].map do |book| + Decorators::Books::Decorator.new book + end + end + + expose :reading do |books| + books["reading"].map do |book| Decorators::Books::Decorator.new book end end diff --git a/config/routes.rb b/config/routes.rb index 772a543..e61f042 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,7 +59,7 @@ module Adamantium get "/podcasts", to: "podcasts.index" - get "/books", to: "books.index" + get "/bookshelf", to: "books.index" redirect "deploying-a-hanami-app-to-fly-io", to: "/post/deploying-a-hanami-20-app-to-flyio" redirect "deploying-a-hanami-app-to-fly-io/", to: "/post/deploying-a-hanami-20-app-to-flyio" diff --git a/tailwind.config.js b/tailwind.config.js index 95ce749..cfbc831 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -3,7 +3,7 @@ const colors = require("tailwindcss/colors"); module.exports = { - content: ["./app/templates/**/*.slim", "./public/assets/index.js"], + content: ["./app/templates/**/*.slim", "./public/assets/index.js", "app/decorators/*/decorator.rb"], theme: { fontSize: { xsm: '0.75rem',