diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 628418557c..fe737810d5 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -18,7 +18,6 @@ class CollectionsController < ApplicationController respond_to do |format| format.html do expires_in expiration_duration, public: true unless user_signed_in? - render template: 'home/index' end format.json do diff --git a/app/views/collections/show.html.haml b/app/views/collections/show.html.haml new file mode 100644 index 0000000000..176d422396 --- /dev/null +++ b/app/views/collections/show.html.haml @@ -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' diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 55ad344b80..21b56c27cd 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -92,6 +92,7 @@ RSpec.configure do |config| config.include CommandLineHelpers, type: :cli config.include SystemHelpers, type: :system config.include Shoulda::Matchers::ActiveModel, type: :validator + config.include HtmlHeadInspection, type: :request # TODO: Remove when Devise fixes https://github.com/heartcombo/devise/issues/5705 config.before do diff --git a/spec/requests/account_show_page_spec.rb b/spec/requests/account_show_page_spec.rb index 7f3ea2595f..e45c97801d 100644 --- a/spec/requests/account_show_page_spec.rb +++ b/spec/requests/account_show_page_spec.rb @@ -16,18 +16,4 @@ RSpec.describe 'The account show page' do expect(head_meta_content('og:image')).to match '.+' expect(head_meta_content('og:url')).to eq short_account_url(username: alice.username) 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 diff --git a/spec/requests/collections_spec.rb b/spec/requests/collections_spec.rb index dbdf1c16a2..72622b5cab 100644 --- a/spec/requests/collections_spec.rb +++ b/spec/requests/collections_spec.rb @@ -6,12 +6,20 @@ RSpec.describe 'Collections' do describe 'GET /collections/:id' do 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 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 diff --git a/spec/requests/status_show_page_spec.rb b/spec/requests/status_show_page_spec.rb index ac542e841d..03f8f5a42e 100644 --- a/spec/requests/status_show_page_spec.rb +++ b/spec/requests/status_show_page_spec.rb @@ -41,26 +41,5 @@ RSpec.describe 'Statuses' do expect(head_meta_content('og:locale')).to eq 'ca' expect(head_meta_content('og:description')).to eq status_text 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 diff --git a/spec/support/html_head_inspection.rb b/spec/support/html_head_inspection.rb new file mode 100644 index 0000000000..677bffe907 --- /dev/null +++ b/spec/support/html_head_inspection.rb @@ -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