A platform for community discussion. Free, open, simple.
UX: Add og metadata for groups.
Maja Komel76a2fc3d0782
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rbindex 74f5479d261..7ba55917fee 100644--- a/app/controllers/groups_controller.rb+++ b/app/controllers/groups_controller.rb@@ -12,6 +12,7 @@ class GroupsController < ApplicationController]skip_before_action :preload_json, :check_xhr, only: [:posts_feed, :mentions_feed]+ skip_before_action :check_xhr, only: [:show]def indexunless SiteSetting.enable_group_directory?@@ -48,7 +49,19 @@ class GroupsController < ApplicationControllerenddef show- render_serialized(find_group(:id), GroupShowSerializer, root: 'basic_group')+ respond_to do |format|+ group = find_group(:id)++ format.html do+ @title = group.full_name.present? ? group.full_name.capitalize : group.name+ @description_meta = group.bio_cooked.present? ? PrettyText.excerpt(group.bio_cooked, 300) : @title+ render :show+ end++ format.json do+ render_serialized(group, GroupShowSerializer, root: 'basic_group')+ end+ endenddef editdiff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erbnew file mode 100644index 00000000000..cc250d46849--- /dev/null+++ b/app/views/groups/show.html.erb@@ -0,0 +1,3 @@+<% content_for :head do %>+ <%= raw crawlable_meta_data(title: @title, description: @description_meta) %>+<% end %>diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rbindex 6aff1275094..dc68c61f002 100644--- a/spec/requests/groups_controller_spec.rb+++ b/spec/requests/groups_controller_spec.rb@@ -57,6 +57,24 @@ describe GroupsController doendend+ describe '#show' do+ it 'should respond to HTML' do+ group.update_attribute(:bio_cooked, 'testing group bio')++ get "/groups/#{group.name}.html"++ expect(response.status).to eq(200)++ expect(response.body).to have_tag(:meta, with: {+ property: 'og:title', content: group.name+ })++ expect(response.body).to have_tag(:meta, with: {+ property: 'og:description', content: group.bio_cooked+ })+ end+ end+describe '#mentionable' doit "should return the right response" dosign_in(user)@@ -226,7 +244,7 @@ describe GroupsController doendend- describe "edit" do+ describe "#edit" dolet(:group) { Fabricate(:group) }context 'when user is not signed in' do