diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index d6eb11d..6fab66d 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class BooksController < ApplicationController + # NOTE: Remember to see .jbuilder def index @books = Book.all end diff --git a/app/models/chapter.rb b/app/models/chapter.rb index d0e68f4..696ed05 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -43,6 +43,18 @@ def copy_paste_info Rails.logger.debug info end + def copy_paste_artwork_alt_text + info = <<~HEREDOC + {https://spg.dev/chapters/#{self.id}} + + Artwork for chapter #{self.number} of #{self.book.en_title}, titled: “#{self.en_title}.” + + #{self.en_short_summary} + HEREDOC + + Rails.logger.debug info + end + def csv_rows file_path = "lib/imports/#{self.book.sequence}/#{self.number}.csv" diff --git a/app/views/books/index.json.jbuilder b/app/views/books/index.json.jbuilder index ed103ef..1e0c869 100644 --- a/app/views/books/index.json.jbuilder +++ b/app/views/books/index.json.jbuilder @@ -3,5 +3,5 @@ json.key_format! :camelize => :lower json.books do - json.array!(@books, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released) + json.array!(@books, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released, :slug) end diff --git a/app/views/books/show.json.jbuilder b/app/views/books/show.json.jbuilder index 2e308c6..e3911ed 100644 --- a/app/views/books/show.json.jbuilder +++ b/app/views/books/show.json.jbuilder @@ -3,6 +3,6 @@ json.key_format! :camelize => :lower json.book do - # :book => {:id, :sequence, :title, :enTitle, :enShortSummary, :enSynopsis, :artworkUrl, :numberOfChaptersReleased } - json.call(@book, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released) + # :book => {:id, :sequence, :title, :enTitle, :enShortSummary, :enSynopsis, :artworkUrl, :numberOfChaptersReleased, :slug } + json.call(@book, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released, :slug) end diff --git a/db/migrate/20240214064320_add_slug_to_books.rb b/db/migrate/20240214064320_add_slug_to_books.rb new file mode 100644 index 0000000..3ff00cf --- /dev/null +++ b/db/migrate/20240214064320_add_slug_to_books.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class AddSlugToBooks < ActiveRecord::Migration[7.0] + def change + add_column :books, :slug, :string + add_index :books, :slug, :unique => true + + slug_mappings = [ + { :id => 1, :slug => 'nanak-prakash-purbardh' }, + { :id => 2, :slug => 'nanak-prakash-utrardh' }, + { :id => 3, :slug => 'raas-1' }, + { :id => 4, :slug => 'raas-2' }, + { :id => 5, :slug => 'raas-3' }, + { :id => 6, :slug => 'raas-4' }, + { :id => 7, :slug => 'raas-5' }, + { :id => 8, :slug => 'raas-6' }, + { :id => 9, :slug => 'raas-7' }, + { :id => 10, :slug => 'raas-8' }, + { :id => 11, :slug => 'raas-9' }, + { :id => 12, :slug => 'raas-10' }, + { :id => 13, :slug => 'raas-11' }, + { :id => 14, :slug => 'raas-12' }, + { :id => 15, :slug => 'rut-1' }, + { :id => 16, :slug => 'rut-2' }, + { :id => 17, :slug => 'rut-3' }, + { :id => 18, :slug => 'rut-4' }, + { :id => 19, :slug => 'rut-5' }, + { :id => 20, :slug => 'rut-6' }, + { :id => 21, :slug => 'ayaan-1' }, + { :id => 22, :slug => 'ayaan-2' } + ] + + reversible do |dir| + dir.up do + slug_mappings.each do |mapping| + Book.find_by(:id => mapping[:id])&.update(:slug => mapping[:slug]) + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 03777dd..71c6642 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_06_11_191536) do +ActiveRecord::Schema[7.0].define(version: 2024_02_14_064320) do create_table "books", force: :cascade do |t| t.integer "sequence", null: false t.string "title", null: false @@ -20,6 +20,8 @@ t.text "artwork_url" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "slug" + t.index ["slug"], name: "index_books_on_slug", unique: true end create_table "chapter_kathas", force: :cascade do |t|