Skip to content

Commit 261deed

Browse files
authored
Add robots meta tag helper and flag private pages as noindex (#1028)
## Summary - add `robots_meta_tag` helper with `content_for` override - include robots meta tag in standard layouts - mark auth-only controllers as noindex via new helper and tests ## Testing - `bundle exec rubocop` - `bundle exec brakeman -q -w2` - `bundle exec bundler-audit --update` - `bin/codex_style_guard` - `bin/ci` - `DATABASE_URL=postgis://postgres:postgres@localhost/community_engine_test bundle exec rspec spec/helpers/better_together/application_helper_spec.rb` ------ https://chatgpt.com/codex/tasks/task_e_689b7bb862c8832193bc115a7923001c
2 parents 9ca8901 + 1cc1bca commit 261deed

File tree

10 files changed

+37
-0
lines changed

10 files changed

+37
-0
lines changed

app/controllers/better_together/application_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def valid_platform_invitation_token_present?
129129

130130
private
131131

132+
def disallow_robots
133+
view_context.content_for(:meta_robots, 'noindex,nofollow')
134+
end
135+
132136
def render_not_found
133137
render 'errors/404', status: :not_found
134138
end

app/controllers/better_together/content/blocks_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Content
55
# CRUD for content blocks independently of pages
66
class BlocksController < ResourceController
77
before_action :authenticate_user!
8+
before_action :disallow_robots
89
before_action :set_block, only: %i[show edit update destroy]
910
before_action only: %i[index], if: -> { Rails.env.development? } do
1011
# Make sure that all BLock subclasses are loaded in dev to generate new block buttons

app/controllers/better_together/content/page_blocks_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Content
55
# CRUD for page blocks
66
class PageBlocksController < ApplicationController
77
before_action :authenticate_user!
8+
before_action :disallow_robots
89
before_action :set_page
910

1011
def new

app/controllers/better_together/conversations_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module BetterTogether
44
# Handles managing conversations
55
class ConversationsController < ApplicationController
66
before_action :authenticate_user!
7+
before_action :disallow_robots
78
before_action :set_conversations, only: %i[index new show]
89
before_action :set_conversation, only: %i[show]
910

app/controllers/better_together/messages_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module BetterTogether
44
# handles managing messages
55
class MessagesController < ApplicationController
66
before_action :authenticate_user!
7+
before_action :disallow_robots
78
before_action :set_conversation
89

910
def create

app/controllers/better_together/notifications_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module BetterTogether
44
# handles rendering and marking notifications as read
55
class NotificationsController < ApplicationController
66
before_action :authenticate_user!
7+
before_action :disallow_robots
78

89
def index
910
@notifications = helpers.current_person.notifications.includes(:event).order(created_at: :desc)

app/helpers/better_together/application_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ def seo_meta_tags # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
102102
end
103103
# rubocop:enable Metrics/MethodLength
104104

105+
def robots_meta_tag(content = 'index,follow')
106+
meta_content = content_for?(:meta_robots) ? content_for(:meta_robots) : content
107+
tag.meta(name: 'robots', content: meta_content)
108+
end
109+
105110
# Builds Open Graph meta tags for the current view using content blocks when
106111
# provided. Falls back to localized defaults and the host community logo.
107112
# rubocop:todo Metrics/PerceivedComplexity

app/views/layouts/better_together/application.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<title><%= (yield(:page_title) + ' | ') if content_for?(:page_title) %><%= host_platform.name %></title>
1313
<%= open_graph_meta_tags %>
1414
<%= seo_meta_tags %>
15+
<%= robots_meta_tag %>
1516
<meta name="color-scheme" content="light dark">
1617
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1718
<%= csrf_meta_tags %>

app/views/layouts/better_together/turbo_native.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<title><%= (yield(:page_title) + ' | ') if content_for?(:page_title) %><%= host_platform.name %></title>
1313
<%= open_graph_meta_tags %>
1414
<%= seo_meta_tags %>
15+
<%= robots_meta_tag %>
1516
<meta name="color-scheme" content="light dark">
1617
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1718
<%= csrf_meta_tags %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
module BetterTogether
6+
RSpec.describe ApplicationHelper, type: :helper do
7+
describe '#robots_meta_tag' do
8+
it 'renders default robots meta tag' do
9+
tag = helper.robots_meta_tag
10+
expect(tag).to include('name="robots"')
11+
expect(tag).to include('content="index,follow"')
12+
end
13+
14+
it 'allows override via content_for' do
15+
view.content_for(:meta_robots, 'noindex,nofollow')
16+
tag = helper.robots_meta_tag
17+
expect(tag).to include('content="noindex,nofollow"')
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)