diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index cac5b0ba8f67a1ce6f3c1b2c08c09e2a7c225c5f..a3f5a008b8f772d26eef7b0f4db6087d6997c098 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -39,6 +39,7 @@ class Settings::PreferencesController < ApplicationController :setting_delete_modal, :setting_auto_play_gif, :setting_system_font_ui, + :setting_noindex, notification_emails: %i(follow follow_request reblog favourite mention digest), interactions: %i(must_be_follower must_be_following) ) diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index e0e92b19d06d1c9a247b4196b5531cee3980c4f1..c5da180291f23a85e6e1ba4b9ba69debe3a292d8 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -23,6 +23,7 @@ class UserSettingsDecorator user.settings['delete_modal'] = delete_modal_preference user.settings['auto_play_gif'] = auto_play_gif_preference user.settings['system_font_ui'] = system_font_ui_preference + user.settings['noindex'] = noindex_preference end def merged_notification_emails @@ -57,6 +58,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_auto_play_gif' end + def noindex_preference + boolean_cast_setting 'setting_noindex' + end + def boolean_cast_setting(key) settings[key] == '1' end diff --git a/app/models/user.rb b/app/models/user.rb index a63b1da7f164e849056e91db3a223a4f37db0c8b..becf0018fbec41aef1c8036f33846bcec7a41e77 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -99,6 +99,10 @@ class User < ApplicationRecord settings.system_font_ui end + def setting_noindex + settings.noindex + end + def activate_session(request) session_activations.activate(session_id: SecureRandom.hex, user_agent: request.user_agent, diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml index a1904910358397a35cf2de4086e54c8d950e0efb..7ed634e5d28e7c90a166d8a85672542ba1ff3025 100644 --- a/app/views/accounts/show.html.haml +++ b/app/views/accounts/show.html.haml @@ -2,6 +2,9 @@ = display_name(@account) - content_for :header_tags do + - if @account.user&.setting_noindex + %meta{ name: 'robots', content: 'noindex' }/ + %link{ rel: 'salmon', href: api_salmon_url(@account.id) }/ %link{ rel: 'alternate', type: 'application/atom+xml', href: account_url(@account, format: 'atom') }/ diff --git a/app/views/follower_accounts/index.html.haml b/app/views/follower_accounts/index.html.haml index 89c7f3a29476908442de780c257ca2d7519e88ee..738b3163817aa1aaa7172e3bc89e7f4825406750 100644 --- a/app/views/follower_accounts/index.html.haml +++ b/app/views/follower_accounts/index.html.haml @@ -2,6 +2,9 @@ = t('accounts.people_who_follow', name: display_name(@account)) - content_for :header_tags do + - if @account.user&.setting_noindex + %meta{ name: 'robots', content: 'noindex' }/ + = render 'accounts/og', account: @account, url: account_followers_url(@account, only_path: false) = render 'accounts/header', account: @account diff --git a/app/views/following_accounts/index.html.haml b/app/views/following_accounts/index.html.haml index 6f0de7590ba5a5ebe0254c58a7ea91959bf194ec..9637c689f99fa5206e1ba5ac860a66cd6b5771d5 100644 --- a/app/views/following_accounts/index.html.haml +++ b/app/views/following_accounts/index.html.haml @@ -2,6 +2,9 @@ = t('accounts.people_followed_by', name: display_name(@account)) - content_for :header_tags do + - if @account.user&.setting_noindex + %meta{ name: 'robots', content: 'noindex' }/ + = render 'accounts/og', account: @account, url: account_followers_url(@account, only_path: false) = render 'accounts/header', account: @account diff --git a/app/views/layouts/embedded.html.haml b/app/views/layouts/embedded.html.haml index 4826f32f75fd4fbbca426da777cc107b850ba5cb..46dab2d0fa2d5e77b7b1b90ed1fccc84061a90e1 100644 --- a/app/views/layouts/embedded.html.haml +++ b/app/views/layouts/embedded.html.haml @@ -2,6 +2,8 @@ %html{ lang: I18n.locale } %head %meta{ charset: 'utf-8' }/ + %meta{ name: 'robots', content: 'noindex' }/ + = stylesheet_pack_tag 'common', media: 'all' = javascript_pack_tag 'common', integrity: true, crossorigin: 'anonymous' = javascript_pack_tag "locale_#{I18n.locale}", integrity: true, crossorigin: 'anonymous' diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index 56a261ab65d423a39a5b9ae919a067df4b24d0f7..3b5d90942a895c11ad95515440d31de6dd686a62 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -40,6 +40,9 @@ = ff.input :must_be_follower, as: :boolean, wrapper: :with_label = ff.input :must_be_following, as: :boolean, wrapper: :with_label + .fields-group + = f.input :setting_noindex, as: :boolean, wrapper: :with_label + .fields-group = f.input :setting_boost_modal, as: :boolean, wrapper: :with_label = f.input :setting_delete_modal, as: :boolean, wrapper: :with_label diff --git a/app/views/stream_entries/show.html.haml b/app/views/stream_entries/show.html.haml index d01e82af8fffdd1fef10a09378361cc75b59c3af..80ea30eb169d3962fba3bdc015fffed00abea0be 100644 --- a/app/views/stream_entries/show.html.haml +++ b/app/views/stream_entries/show.html.haml @@ -1,4 +1,7 @@ - content_for :header_tags do + - if @account.user&.setting_noindex + %meta{ name: 'robots', content: 'noindex' }/ + %link{ rel: 'alternate', type: 'application/atom+xml', href: account_stream_entry_url(@account, @stream_entry, format: 'atom') }/ %link{ rel: 'alternate', type: 'application/json+oembed', href: api_oembed_url(url: account_stream_entry_url(@account, @stream_entry), format: 'json') }/ diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index e3f784a1a781c304d512ca5eec18e9f4f71f4e3a..fbaf0ff68928e10ce2c236abdd32166192aba063 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -12,6 +12,7 @@ en: note: one: <span class="note-counter">1</span> character left other: <span class="note-counter">%{count}</span> characters left + setting_noindex: Affects your public profile and status pages imports: data: CSV file exported from another Mastodon instance sessions: @@ -41,6 +42,7 @@ en: setting_default_sensitive: Always mark media as sensitive setting_delete_modal: Show confirmation dialog before deleting a toot setting_system_font_ui: Use system's default font + setting_noindex: Opt-out of search engine indexing severity: Severity type: Import type username: Username diff --git a/config/settings.yml b/config/settings.yml index 579ba2929ad64d594fd8673ad28be44f2faf6d38..d239fb6a65b8177765d0935161fa3899f5ab2ede 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -21,6 +21,7 @@ defaults: &defaults auto_play_gif: false delete_modal: true system_font_ui: false + noindex: false notification_emails: follow: false reblog: false