Skip to content

Commit

Permalink
remove tophat
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoneill committed Nov 5, 2024
1 parent d167c89 commit 54a2379
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 75 deletions.
1 change: 0 additions & 1 deletion app/controllers/spotlight/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class CatalogController < ::CatalogController
if Blacklight::VERSION > '8'
blacklight_config.show.document_component = Spotlight::DocumentComponent
else
blacklight_config.show.partials.unshift 'tophat'
blacklight_config.show.partials.unshift 'curation_mode_toggle'
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/spotlight/main_app_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def link_back_to_catalog(opts = { label: nil })

# Expecting to upstream this override in https://github.com/projectblacklight/blacklight/pull/3343/files
def document_presenter(document, view_config: nil, **kwargs)
(view_config&.document_presenter_class || document_presenter_class(document)).new(document, self, view_config: view_config, **kwargs)
(view_config&.document_presenter_class || document_presenter_class(document)).new(document, self, view_config:, **kwargs)
end

def document_presenter_class(_document)
Expand Down
95 changes: 59 additions & 36 deletions app/helpers/spotlight/meta_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@
module Spotlight
# HTML <meta> tag helpers
module MetaHelper
def description(description)
content_for(:meta) { ActionController::Base.helpers.tag.meta(name: 'description', content: description) } if description
end

def card(type, &block)
card = {}
block.call(card) if block_given?
content_for(:meta) { build_tags(card, type) }
end

# rubocop:disable Rails/OutputSafety
def build_tags(attributes, tag_field)
type_fields = { 'og' => 'property', 'twitter' => 'name' }
attributes.map do |key, value|
ActionController::Base.helpers.tag.meta("#{type_fields[tag_field]}": "#{tag_field}:#{key}", content: value) if value
end.compact.join("\n").html_safe
end
# rubocop:enable Rails/OutputSafety

def add_exhibit_meta_content
exhibit_twitter_card_content
exhibit_opengraph_content
end

def exhibit_twitter_card_content
twitter_card('summary') do |card|
card.url exhibit_root_url(current_exhibit)
card.title current_exhibit.title
card.description current_exhibit.subtitle
card.image meta_image if current_exhibit.thumbnail
card('twitter') do |card|
card['card'] = 'summary'
card['url'] = exhibit_root_url(current_exhibit)
card['title'] = current_exhibit.title
card['description'] = current_exhibit.subtitle
card['image'] = meta_image if current_exhibit.thumbnail
end
end

Expand All @@ -22,10 +42,10 @@ def meta_image
end

def exhibit_opengraph_content
opengraph do |graph|
graph.title current_exhibit.title
graph.image meta_image if current_exhibit.thumbnail
graph.site_name site_title
card('og') do |graph|
graph['title'] = current_exhibit.title
graph['image'] = meta_image if current_exhibit.thumbnail
graph['site_name'] = site_title
end
end

Expand All @@ -35,20 +55,21 @@ def add_page_meta_content(page)
end

def page_twitter_card_content(page)
twitter_card('summary_large_image') do |card|
card.title page.title
card.image page.thumbnail.iiif_url if page.thumbnail
card('twitter') do |card|
card['card'] = 'summary_large_image'
card['title'] = page.title
card['image'] = page.thumbnail.iiif_url if page.thumbnail
end
end

def page_opengraph_content(page)
opengraph do |graph|
graph.type 'article'
graph.site_name application_name
graph.title page.title
graph.send('image', page.thumbnail.iiif_url) if page.thumbnail
graph.send('article:published_time', page.created_at.iso8601)
graph.send('article:modified_time', page.updated_at.iso8601)
card('og') do |graph|
graph['type'] = 'article'
graph['site_name'] = application_name
graph['title'] = page.title
graph['image'] = page.thumbnail.iiif_url if page.thumbnail
graph['article:published_time'] = page.created_at.iso8601
graph['article:modified_time'] = page.updated_at.iso8601
end
end

Expand All @@ -58,20 +79,21 @@ def add_browse_meta_content(browse)
end

def browse_twitter_card_content(browse)
twitter_card('summary_large_image') do |card|
card.title browse.title
card.image browse.thumbnail.iiif_url if browse.thumbnail
card('twitter') do |card|
card['card'] = 'summary_large_image'
card['title'] = browse.title
card['image'] = browse.thumbnail.iiif_url if browse.thumbnail
end
end

def browse_opengraph_content(browse)
opengraph do |graph|
graph.type 'article'
graph.site_name application_name
graph.title browse.title
graph.send('image', browse.thumbnail.iiif_url) if browse.thumbnail
graph.send('article:published_time', browse.created_at.iso8601)
graph.send('article:modified_time', browse.updated_at.iso8601)
card('og') do |graph|
graph['type'] = 'article'
graph['site_name'] = application_name
graph['title'] = browse.title
graph['image'] = browse.thumbnail.iiif_url if browse.thumbnail
graph['article:published_time'] = browse.created_at.iso8601
graph['article:modified_time'] = browse.updated_at.iso8601
end
end

Expand All @@ -83,19 +105,20 @@ def add_document_meta_content(document)
def document_twitter_card_content(document)
presenter = document_presenter(document)

twitter_card('summary_large_image') do |card|
card.title presenter.heading
card.image document.first(blacklight_config.index.thumbnail_field)
card('twitter') do |card|
card['card'] = 'summary_large_image'
card['title'] = presenter.heading
card['image'] = document.first(blacklight_config.index.thumbnail_field)
end
end

def document_opengraph_content(document)
presenter = document_presenter(document)

opengraph do |graph|
graph.site_name application_name
graph.title presenter.heading
graph.send('image', document.first(blacklight_config.index.thumbnail_field))
card('og') do |graph|
graph['site_name'] = application_name
graph['title'] = presenter.heading
graph['image'] = document.first(blacklight_config.index.thumbnail_field)
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions app/views/layouts/spotlight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= content_for(:head) %>
<%= description %>
<%= twitter_card %>
<%= opengraph %>
<% if current_exhibit %>
<% description(current_exhibit.description) if current_exhibit %>
<% add_exhibit_meta_content %>
<% end %>
<%= yield(:meta) %>
<%= javascript_tag "Spotlight.sirTrevorIcon = '#{asset_path('spotlight/blocks/sir-trevor-icons.svg')}'" %>
<%= javascript_tag '$.fx.off = true;' if Rails.env.test? %>
</head>
Expand Down
1 change: 0 additions & 1 deletion app/views/spotlight/browse/_tophat.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/spotlight/browse/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% set_html_page_title @search.title %>
<% render partial: 'tophat' %>
<% add_browse_meta_content(@search) %>
<%= exhibit_edit_link @search, class: 'edit-button float-right float-end btn btn-primary' if can? :edit, @search %>
<% if resource_masthead? %>
Expand Down
2 changes: 0 additions & 2 deletions app/views/spotlight/home_pages/_tophat.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/spotlight/pages/_tophat.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/spotlight/pages/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% set_html_page_title @page.title if @page.should_display_title? %>
<% render 'tophat' %>
<% add_page_meta_content(@page) %>
<% content_for(:sidebar) do %>
<%= render 'sidebar' %>
Expand Down
1 change: 0 additions & 1 deletion blacklight-spotlight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ these collections.)
s.add_dependency 'roar', '~> 1.1'
s.add_dependency 'roar-rails'
s.add_dependency 'signet'
s.add_dependency 'tophat'
s.add_dependency 'view_component', '>= 2.66', '< 4'

s.add_development_dependency 'capybara', '~> 3.31'
Expand Down
1 change: 0 additions & 1 deletion lib/spotlight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
require 'riiif'
require 'spotlight/riiif_service'
require 'spotlight/upload_field_config'
require 'tophat'

module Spotlight
##
Expand Down
5 changes: 1 addition & 4 deletions spec/features/browse_category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,9 @@
end

it 'has <meta> tags' do
TopHat.current['twitter_card'] = nil
TopHat.current['opengraph'] = nil

visit spotlight.exhibit_browse_path(exhibit, search)

expect(page).to have_css "meta[name='twitter:title'][value='#{search.title}']", visible: false
expect(page).to have_css "meta[name='twitter:title'][content='#{search.title}']", visible: false
expect(page).to have_css "meta[property='og:site_name']", visible: false
expect(page).to have_css "meta[property='og:title'][content='#{search.title}']", visible: false
end
Expand Down
3 changes: 1 addition & 2 deletions spec/features/display_within_exhibit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
end

it 'has <meta> tags' do
TopHat.current['twitter_card'] = nil
TopHat.current['opengraph'] = nil
Spotlight::Site.instance.update(title: 'some title')

visit spotlight.exhibit_solr_document_path(exhibit, 'dq287tq6352')

Expand Down
5 changes: 1 addition & 4 deletions spec/features/feature_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
end

it 'has <meta> tags' do
TopHat.current['twitter_card'] = nil
TopHat.current['opengraph'] = nil

visit spotlight.exhibit_feature_page_path(feature_page.exhibit, feature_page)

expect(page).to have_css "meta[name='twitter:title'][value='#{feature_page.title}']", visible: false
expect(page).to have_css "meta[name='twitter:title'][content='#{feature_page.title}']", visible: false
expect(page).to have_css "meta[property='og:site_name']", visible: false
expect(page).to have_css "meta[property='og:type'][content='article']", visible: false
expect(page).to have_css "meta[property='og:title'][content='#{feature_page.title}']", visible: false
Expand Down
6 changes: 2 additions & 4 deletions spec/features/home_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@
end

it 'has <meta> tags' do
TopHat.current['twitter_card'] = nil
TopHat.current['opengraph'] = nil
Spotlight::Site.instance.update(title: 'some title')

visit spotlight.exhibit_home_page_path(exhibit)

expect(page).to have_css "meta[name='twitter:card'][value='summary']", visible: false
expect(page).to have_css "meta[name='twitter:url'][value='#{spotlight.exhibit_root_url(exhibit)}']", visible: false
expect(page).to have_css "meta[name='twitter:card'][content='summary']", visible: false
expect(page).to have_css "meta[name='twitter:url'][content='#{spotlight.exhibit_root_url(exhibit)}']", visible: false
expect(page).to have_css "meta[property='og:site_name'][content='#{Spotlight::Site.instance.title}']", visible: false
end

Expand Down
16 changes: 6 additions & 10 deletions spec/helpers/spotlight/meta_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
allow(helper).to receive(:site_title).and_return('some title')
current_exhibit.subtitle = 'xyz'
current_exhibit.description = 'abc'
TopHat.current['twitter_card'] = nil
TopHat.current['opengraph'] = nil
end

it 'generates a twitter card for the exhibit' do
Expand All @@ -19,15 +17,13 @@

helper.add_exhibit_meta_content

card = helper.twitter_card
expect(card).to have_css "meta[name='twitter:card'][value='summary']", visible: false
expect(card).to have_css "meta[name='twitter:url'][value='some/url']", visible: false
expect(card).to have_css "meta[name='twitter:title'][value='#{current_exhibit.title}']", visible: false
expect(card).to have_css "meta[name='twitter:description'][value='#{current_exhibit.subtitle}']", visible: false
expect(card).to have_css "meta[name='twitter:image'][value='https://test.host/images/7777/full/400,300/0/default.jpg']", visible: false
expect(view.content_for(:meta)).to include('<meta name="twitter:card" content="summary">')
expect(view.content_for(:meta)).to include('<meta name="twitter:url" content="some/url">')
expect(view.content_for(:meta)).to include("<meta name=\"twitter:title\" content=\"#{current_exhibit.title}\">")
expect(view.content_for(:meta)).to include("<meta name=\"twitter:description\" content=\"#{current_exhibit.subtitle}\">")
expect(view.content_for(:meta)).to include('<meta name="twitter:image" content="https://test.host/images/7777/full/400,300/0/default.jpg">')

graph = helper.opengraph
expect(graph).to have_css "meta[property='og:site_name'][content='some title']", visible: false
expect(view.content_for(:meta)).to include('<meta property="og:site_name" content="some title">')
end
end
end
2 changes: 1 addition & 1 deletion spec/views/spotlight/browse/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
allow(view).to receive_messages(resource_masthead?: false)
allow(view).to receive_messages(blacklight_config: Blacklight::Configuration.new)
allow(view).to receive_messages(render_document_index_with_view: '')
allow(view).to receive_messages(add_browse_meta_content: '')
stub_template('_results_pagination.html.erb' => '')
stub_template('_sort_and_per_page.html.erb' => 'Sort and Per Page actions')
stub_template 'spotlight/browse/_tophat.html.erb' => ''
assign :exhibit, exhibit
assign :search, search
assign :response, double(documents: double(size: 15))
Expand Down
4 changes: 3 additions & 1 deletion spec/views/spotlight/pages/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
allow(view).to receive(:current_exhibit).and_return(exhibit)
allow(view).to receive(:blacklight_config).and_return(Blacklight.default_configuration)
allow(view).to receive(:render_body_class).and_return('')
allow(view).to receive(:add_page_meta_content).and_return('')
allow(view).to receive(:description).and_return('')
assign(:page, page)
stub_template 'spotlight/pages/_sidebar.html.erb' => 'Sidebar'
stub_template 'spotlight/pages/_tophat.html.erb' => ''
end

it 'renders the title as a heading' do
Expand Down Expand Up @@ -47,6 +48,7 @@
stub_template 'shared/_masthead.html.erb' => ''
allow(view).to receive_messages(document_presenter: presenter, action_name: 'show', blacklight_config:)
allow(view).to receive(:search_action_url).and_return('/catalog')
allow(view).to receive(:add_exhibit_meta_content).and_return('')
render template: 'spotlight/pages/show', layout: 'layouts/spotlight/spotlight'
end

Expand Down

0 comments on commit 54a2379

Please sign in to comment.