Add meta tags to Collection HTML (#39357)
This commit is contained in:
parent
bcb8553e01
commit
70bb70c2e6
@ -18,7 +18,6 @@ class CollectionsController < ApplicationController
|
|||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
expires_in expiration_duration, public: true unless user_signed_in?
|
expires_in expiration_duration, public: true unless user_signed_in?
|
||||||
render template: 'home/index'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
format.json do
|
format.json do
|
||||||
|
|||||||
20
app/views/collections/show.html.haml
Normal file
20
app/views/collections/show.html.haml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
- content_for :page_title, @collection.name
|
||||||
|
|
||||||
|
- content_for :header_tags do
|
||||||
|
%meta{ name: 'robots', content: 'noindex, noarchive' }/
|
||||||
|
|
||||||
|
%link{ rel: 'alternate', type: 'application/activity+json', href: ap_account_collection_url(@collection.account_id, @collection) }/
|
||||||
|
%link{ rel: 'alternate', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', href: ap_account_collection_url(@collection.account_id, @collection) }/
|
||||||
|
|
||||||
|
- unless @collection.sensitive?
|
||||||
|
%meta{ name: 'description', content: @collection.description }/
|
||||||
|
= opengraph 'og:description', @collection.description
|
||||||
|
= opengraph 'og:site_name', site_title
|
||||||
|
= opengraph 'og:type', 'website'
|
||||||
|
= opengraph 'og:title', @collection.name
|
||||||
|
= opengraph 'og:url', collection_url(@collection)
|
||||||
|
- if @collection.language.present?
|
||||||
|
= opengraph 'og:locale', @collection.language
|
||||||
|
= opengraph 'twitter:card', 'summary'
|
||||||
|
|
||||||
|
= render 'shared/web_app'
|
||||||
@ -92,6 +92,7 @@ RSpec.configure do |config|
|
|||||||
config.include CommandLineHelpers, type: :cli
|
config.include CommandLineHelpers, type: :cli
|
||||||
config.include SystemHelpers, type: :system
|
config.include SystemHelpers, type: :system
|
||||||
config.include Shoulda::Matchers::ActiveModel, type: :validator
|
config.include Shoulda::Matchers::ActiveModel, type: :validator
|
||||||
|
config.include HtmlHeadInspection, type: :request
|
||||||
|
|
||||||
# TODO: Remove when Devise fixes https://github.com/heartcombo/devise/issues/5705
|
# TODO: Remove when Devise fixes https://github.com/heartcombo/devise/issues/5705
|
||||||
config.before do
|
config.before do
|
||||||
|
|||||||
@ -16,18 +16,4 @@ RSpec.describe 'The account show page' do
|
|||||||
expect(head_meta_content('og:image')).to match '.+'
|
expect(head_meta_content('og:image')).to match '.+'
|
||||||
expect(head_meta_content('og:url')).to eq short_account_url(username: alice.username)
|
expect(head_meta_content('og:url')).to eq short_account_url(username: alice.username)
|
||||||
end
|
end
|
||||||
|
|
||||||
def head_link_icons
|
|
||||||
response
|
|
||||||
.parsed_body
|
|
||||||
.search('html head link[rel=icon]')
|
|
||||||
end
|
|
||||||
|
|
||||||
def head_meta_content(property)
|
|
||||||
response
|
|
||||||
.parsed_body
|
|
||||||
.search("html head meta[property='#{property}']")
|
|
||||||
.attr('content')
|
|
||||||
.text
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,12 +6,20 @@ RSpec.describe 'Collections' do
|
|||||||
describe 'GET /collections/:id' do
|
describe 'GET /collections/:id' do
|
||||||
subject { get collection_path(collection) }
|
subject { get collection_path(collection) }
|
||||||
|
|
||||||
let(:collection) { Fabricate(:collection) }
|
let(:collection) do
|
||||||
|
Fabricate(:collection, name: 'Frequent posters', description: 'Amazing people that can quickly fill your timeline', language: 'en')
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns success' do
|
it 'returns success and includes opengraph meta tags' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
expect(head_meta_content('og:title')).to eq 'Frequent posters'
|
||||||
|
expect(head_meta_content('og:description')).to eq 'Amazing people that can quickly fill your timeline'
|
||||||
|
expect(head_meta_content('og:type')).to eq 'website'
|
||||||
|
expect(head_meta_content('og:url')).to eq collection_url(collection)
|
||||||
|
expect(head_meta_content('og:locale')).to eq 'en'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -41,26 +41,5 @@ RSpec.describe 'Statuses' do
|
|||||||
expect(head_meta_content('og:locale')).to eq 'ca'
|
expect(head_meta_content('og:locale')).to eq 'ca'
|
||||||
expect(head_meta_content('og:description')).to eq status_text
|
expect(head_meta_content('og:description')).to eq status_text
|
||||||
end
|
end
|
||||||
|
|
||||||
def head_link_icons
|
|
||||||
response
|
|
||||||
.parsed_body
|
|
||||||
.search('html head link[rel=icon]')
|
|
||||||
end
|
|
||||||
|
|
||||||
def head_meta_content(property)
|
|
||||||
response
|
|
||||||
.parsed_body
|
|
||||||
.search("html head meta[property='#{property}']")
|
|
||||||
.attr('content')
|
|
||||||
.text
|
|
||||||
end
|
|
||||||
|
|
||||||
def head_meta_exists(property)
|
|
||||||
!response
|
|
||||||
.parsed_body
|
|
||||||
.search("html head meta[property='#{property}']")
|
|
||||||
.empty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
24
spec/support/html_head_inspection.rb
Normal file
24
spec/support/html_head_inspection.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module HtmlHeadInspection
|
||||||
|
def head_link_icons
|
||||||
|
response
|
||||||
|
.parsed_body
|
||||||
|
.search('html head link[rel=icon]')
|
||||||
|
end
|
||||||
|
|
||||||
|
def head_meta_content(property)
|
||||||
|
response
|
||||||
|
.parsed_body
|
||||||
|
.search("html head meta[property='#{property}']")
|
||||||
|
.attr('content')
|
||||||
|
.text
|
||||||
|
end
|
||||||
|
|
||||||
|
def head_meta_exists(property)
|
||||||
|
!response
|
||||||
|
.parsed_body
|
||||||
|
.search("html head meta[property='#{property}']")
|
||||||
|
.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user