Skip to content

Commit

Permalink
Term videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed May 3, 2024
1 parent d7acc44 commit 8120ef9
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 21 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
GIT
remote: https://github.com/excid3/madmin.git
revision: 247256623b0c54f0a354d8a0834b9c3c9d513a7a
revision: cc6cd36ca4a64cb5b75a829fffd41b7948afde6c
specs:
madmin (1.2.9)
madmin (1.2.10)
pagy (>= 3.5)
rails (>= 6.0.3)

Expand All @@ -15,7 +15,7 @@ GIT

GIT
remote: https://github.com/rails/rails.git
revision: cc7f0b0d4cabc4807a271a6dfa22150943c80412
revision: 793ff00442723b2ff9ed7b7fb39cae2f5608cc2b
branch: main
specs:
actioncable (7.2.0.alpha)
Expand Down Expand Up @@ -103,7 +103,7 @@ GIT
railties (7.2.0.alpha)
actionpack (= 7.2.0.alpha)
activesupport (= 7.2.0.alpha)
irb
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
Expand Down Expand Up @@ -177,8 +177,8 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
irb (1.12.0)
rdoc
irb (1.13.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.12.0)
actionview (>= 5.0.0)
Expand Down Expand Up @@ -271,7 +271,7 @@ GEM
redis-client (0.22.1)
connection_pool
regexp_parser (2.9.0)
reline (0.5.4)
reline (0.5.5)
io-console (~> 0.5)
rexml (3.2.6)
rubocop (1.63.3)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/terms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class TermsController < ApplicationController
def index
@query = params[:q]

@terms = Term.all
@terms = Term.order(:name)
@terms = @terms.where("name ILIKE :query OR title ILIKE :query", query: "%#{@query}%") if @query.present?
end

Expand Down
34 changes: 22 additions & 12 deletions app/madmin/resources/term_resource.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
class TermResource < Madmin::Resource
# Attributes
attribute :id, form: false
attribute :id, form: false, index: false
attribute :name
attribute :title
attribute :content
attribute :slug
attribute :created_at, form: false
attribute :updated_at, form: false
attribute :created_at, form: false, index: false
attribute :updated_at, form: false, index: false
attribute :video_id
attribute :video_title
attribute :video_description
attribute :video_thumbnail_url
attribute :video_upload_date
attribute :video_duration

def self.model_find(id)
model.find_by!(slug: id)
end

# Associations

# Uncomment this to customize the display name of records in the admin area.
# def self.display_name(record)
# record.name
# end
def self.display_name(record)
record.name
end

# Uncomment this to customize the default sort column and direction.
# def self.default_sort_column
# "created_at"
# end
def self.default_sort_column
"name"
end
#
# def self.default_sort_direction
# "desc"
# end
def self.default_sort_direction
"asc"
end
end
47 changes: 47 additions & 0 deletions app/views/terms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<span class="text-gray-500">Financial Terms / <%= dict_group(@term.name) %> /</span> <%= @term.name %>
</p>
<h1 class="text-3xl font-medium tracking-tight text-center"><%= @term.title %></h1>

<% if @term.video_id.present? %>
<div class="aspect-w-16 aspect-h-9">
<iframe src="https://www.youtube.com/embed/<%=@term.video_id %>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>
<% end %>
<%= markdown @term.content %>
</div>

Expand All @@ -32,3 +39,43 @@
</div>

<%= render "shared/cta_waitlist" %>

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "<%= request.original_url %>"
},
"headline": "<%= @term.name.presence || "#{@term.name} meaning in personal finance" %>",
"description": "<%= markdown(@term.content).gsub(%r{</?[^>]+?>}, '') %>",
"author": {
"@type": "Organization",
"name": "Maybe"
},
"publisher": {
"@type": "Organization",
"name": "Maybe",
"logo": {
"@type": "ImageObject",
"url": "https://maybe.co/apple-icon.png"
}
},
"datePublished": "<%= @term.created_at.iso8601 %>"
}
</script>
<% if @term.video_id.present? %>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "VideoObject",
"name": "<%= @term.video_title %>",
"description": "<%= @term.video_description %>",
"thumbnailUrl": "<%= @term.video_thumbnail_url %>",
"uploadDate": "<%= @term.video_upload_date %>",
"duration": "<%= @term.video_duration %>",
"embedUrl": "https://www.youtube.com/embed/<%=@term.video_id %>"
}
</script>
<% end %>
10 changes: 10 additions & 0 deletions db/migrate/20240502181717_add_video_to_terms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddVideoToTerms < ActiveRecord::Migration[7.2]
def change
add_column :terms, :video_id, :string
add_column :terms, :video_title, :string
add_column :terms, :video_description, :text
add_column :terms, :video_thumbnail_url, :string
add_column :terms, :video_upload_date, :date
add_column :terms, :video_duration, :string
end
end
8 changes: 7 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8120ef9

Please sign in to comment.