Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions app/views/common/_default_og.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<% title = Space.current_space.default? ? TeSS::Config.site['title'] : Space.current_space.title %>
<% image = Space.current_space.default? ? TeSS::Config.site['logo_open_graph'] : Space.current_space.image&.url %>
<% image ||= TeSS::Config.site['logo'] %>
Comment thread
fbacall marked this conversation as resolved.
Resolved
<% description = strip_tags(Space.current_space.default? ? t('home.subtitle') : render_sanitized_markdown(Space.current_space.description)).strip %>
<% twitter = TeSS::Config.twitter_handle if Space.current_space.default? %>

<% # default twitter meta tags -%>
<%= tag(:meta, name: "twitter:card", content: 'summary_large_image') %>
<%= tag(:meta, name: "twitter:site", content: TeSS::Config.twitter_handle) unless TeSS::Config.twitter_handle.blank? %>
<%= tag(:meta, name: "twitter:image", content: asset_url(TeSS::Config.site['logo'])) %>
<%= tag(:meta, name: "twitter:title", content: TeSS::Config.site['title']) %>
<%= tag(:meta, name: "twitter:description", content: strip_tags(t('home.subtitle'))) %>
<%= tag(:meta, name: "twitter:site", content: twitter) if twitter.present? %>
<%= tag(:meta, name: "twitter:image", content: asset_url(image)) if image.present? %>
<%= tag(:meta, name: "twitter:title", content: title) %>
<%= tag(:meta, name: "twitter:description", content: description) if description.present? %>

<% # default OpenGraph meta tags -%>
<%= tag(:meta, property: "og:url", content: request.original_url) %>
<%= tag(:meta, property: "og:image", content: asset_url(TeSS::Config.site['logo_open_graph'])) %>
<%= tag(:meta, property: "og:title", content: TeSS::Config.site['title']) %>
<%= tag(:meta, property: "og:description", content: strip_tags(t('home.subtitle'))) %>
<%= tag(:meta, property: "og:image", content: asset_url(image)) if image.present? %>
<%= tag(:meta, property: "og:title", content: title) %>
<%= tag(:meta, property: "og:description", content: description) if description.present? %>
2 changes: 1 addition & 1 deletion app/views/layouts/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<% if content_for? :og_header %>
<%= yield :og_header %>
<% else %>
<%= render :partial => 'common/default_og' %>
<%= render partial: 'common/default_og' %>
<% end %>

<% if @bioschemas.present? %>
Expand Down
2 changes: 1 addition & 1 deletion test/config/test_tess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default: &default
sender_email: no-reply@example.com
solr_enabled: false
default_role: registered_user
twitter_handle: '@handle'
twitter_handle: '@test_handle'
announcement_message:
prevent_robot_indexing: false
require_cookie_consent: true
Expand Down
36 changes: 36 additions & 0 deletions test/controllers/static_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,40 @@ class StaticControllerTest < ActionController::TestCase
get :home
assert_select 'head title', text: 'TeSS Test Instance'
end

test 'includes og and twitter meta tags' do
get :home
assert_response :success

assert_select 'meta[name="twitter:card"][content=?]', 'summary_large_image'
assert_select 'meta[name="twitter:site"][content=?]', '@test_handle'
assert_select 'meta[name="twitter:title"][content=?]', 'TeSS Test Instance'
assert_select 'meta[name="twitter:description"][content*=?]', "Search the portal"

assert_select 'meta[property="og:url"][content=?]', 'http://test.host/'
assert_select 'meta[property="og:title"][content=?]', 'TeSS Test Instance'
assert_select 'meta[property="og:description"][content*=?]', "Search the portal"
end

test 'includes og and twitter meta tags for space' do
mock_images
space = spaces(:plants)
space.update!(image_url: 'http://example.com/goblet.png', description: 'Plants in space')

with_host(space.host) do
get :home
assert_response :success

assert_select 'meta[name="twitter:card"][content=?]', 'summary_large_image'
assert_select 'meta[name="twitter:site"]', count: 0
assert_select 'meta[name="twitter:image"][content*=?]', 'goblet.png'
assert_select 'meta[name="twitter:title"][content=?]', 'TeSS Plants Community'
assert_select 'meta[name="twitter:description"][content*=?]', "Plants in space"

assert_select 'meta[property="og:url"][content=?]','http://plants.mytess.training/'
assert_select 'meta[property="og:image"][content*=?]', 'goblet.png'
assert_select 'meta[property="og:title"][content=?]', 'TeSS Plants Community'
assert_select 'meta[property="og:description"][content*=?]', "Plants in space"
end
end
end