diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index b498a1ed..3cdc9fb9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -4,6 +4,7 @@ class HomeController < ApplicationController before_action :authenticate_user! before_action :set_referrer_policy_header before_action :set_initial_state_json + before_action :set_data_for_meta def index @body_classes = 'app-body' @@ -11,17 +12,40 @@ class HomeController < ApplicationController private + def set_data_for_meta + return if find_route_matches + + if params[:username].present? + @account = Account.find_local(params[:username]) + elsif params[:account_username].present? + @account = Account.find_local(params[:account_username]) + + if params[:id].present? && !@account.nil? + @status = @account.statuses.find(params[:id]) + @stream_entry = @status.stream_entry + @type = @stream_entry.activity_type.downcase + end + end + + if request.path.starts_with?('/tags') && params[:tag].present? + @tag = Tag.find_normalized(params[:tag]) + end + + end + def authenticate_user! return if user_signed_in? # if no current user, dont allow to navigate to these paths - matches = request.path.match(/\A\/(home|groups|tags|lists|notifications|explore|follow_requests|blocks|domain_blocks|mutes)/) - - if matches + if find_route_matches redirect_to(homepage_path) end end + def find_route_matches + request.path.match(/\A\/(home|groups|lists|notifications|explore|follow_requests|blocks|domain_blocks|mutes)/) + end + def set_initial_state_json serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer) @initial_state_json = serializable_resource.to_json diff --git a/app/javascript/gabsocial/features/ui/index.js b/app/javascript/gabsocial/features/ui/index.js index 51f0431d..d6eea424 100644 --- a/app/javascript/gabsocial/features/ui/index.js +++ b/app/javascript/gabsocial/features/ui/index.js @@ -194,7 +194,7 @@ class SwitchingColumnsArea extends React.PureComponent { - + diff --git a/app/lib/status_finder.rb b/app/lib/status_finder.rb index 4d1aed29..abc55887 100644 --- a/app/lib/status_finder.rb +++ b/app/lib/status_finder.rb @@ -15,7 +15,7 @@ class StatusFinder case recognized_params[:controller] when 'stream_entries' StreamEntry.find(recognized_params[:id]).status - when 'statuses' + when 'home' Status.find(recognized_params[:id]) else raise ActiveRecord::RecordNotFound @@ -29,7 +29,7 @@ class StatusFinder end def verify_action! - unless recognized_params[:action] == 'show' + unless recognized_params[:action] == 'show' || recognized_params[:action] == 'index' raise ActiveRecord::RecordNotFound end end diff --git a/app/views/accounts/_meta.html.haml b/app/views/accounts/_meta.html.haml new file mode 100644 index 00000000..e3a1ad9f --- /dev/null +++ b/app/views/accounts/_meta.html.haml @@ -0,0 +1,21 @@ +- content_for :page_title do + = "#{display_name(account)} (@#{account.local_username_and_domain}) | #{site_hostname}" + +- content_for :header_tags do + %meta{ name: 'description', content: account_description(account) }/ + + - 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') }/ + %link{ rel: 'alternate', type: 'application/rss+xml', href: account_url(account, format: 'rss') }/ + %link{ rel: 'alternate', type: 'application/activity+json', href: ActivityPub::TagManager.instance.uri_for(account) }/ + + - if older_url + %link{ rel: 'next', href: older_url }/ + - if newer_url + %link{ rel: 'prev', href: newer_url }/ + + = opengraph 'og:type', 'profile' + = render 'accounts/og', account: account, url: short_account_url(account, only_path: false) diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml index e4223119..4a9352d1 100644 --- a/app/views/accounts/show.html.haml +++ b/app/views/accounts/show.html.haml @@ -1,25 +1,4 @@ -- content_for :page_title do - = "#{display_name(@account)} (@#{@account.local_username_and_domain})" - -- content_for :header_tags do - %meta{ name: 'description', content: account_description(@account) }/ - - - 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') }/ - %link{ rel: 'alternate', type: 'application/rss+xml', href: account_url(@account, format: 'rss') }/ - %link{ rel: 'alternate', type: 'application/activity+json', href: ActivityPub::TagManager.instance.uri_for(@account) }/ - - - if @older_url - %link{ rel: 'next', href: @older_url }/ - - if @newer_url - %link{ rel: 'prev', href: @newer_url }/ - - = opengraph 'og:type', 'profile' - = render 'og', account: @account, url: short_account_url(@account, only_path: false) - += render 'accounts/meta', account: @account, newer_url: @newer_url, older_url: @older_url = render 'header', account: @account, with_bio: true diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 220a4ca9..02531293 100755 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -18,6 +18,13 @@ %meta{ name: 'theme-color', content: '#282c37' }/ %meta{ name: 'apple-mobile-web-app-capable', content: 'yes' }/ + - if @tag + = render 'tags/meta', tag: @tag, initial_state_json: @initial_state_json + - elsif @stream_entry && @account + = render 'stream_entries/meta', stream_entry: @stream_entry, account: @account + - elsif @account + = render 'accounts/meta', account: @account, older_url: nil, newer_url: nil + %title= content_for?(:page_title) ? safe_join([yield(:page_title).chomp.html_safe, title], ' - ') : title = stylesheet_pack_tag 'common', media: 'all' diff --git a/app/views/stream_entries/_detailed_status.html.haml b/app/views/stream_entries/_detailed_status.html.haml index 23f2920d..226ed5f8 100644 --- a/app/views/stream_entries/_detailed_status.html.haml +++ b/app/views/stream_entries/_detailed_status.html.haml @@ -75,4 +75,4 @@ - if user_signed_in? · - = link_to t('statuses.open_in_web'), web_url("statuses/#{status.id}"), class: 'detailed-status__application', target: '_blank' + = link_to t('statuses.open_in_web'), web_url("#{status.account.acct}/posts/#{status.id}"), class: 'detailed-status__application', target: '_blank' diff --git a/app/views/stream_entries/_meta.html.haml b/app/views/stream_entries/_meta.html.haml new file mode 100644 index 00000000..1e2ded94 --- /dev/null +++ b/app/views/stream_entries/_meta.html.haml @@ -0,0 +1,18 @@ +- content_for :page_title do + = t('statuses.title', name: display_name(account), quote: truncate(stream_entry.activity.spoiler_text.presence || stream_entry.activity.text, length: 50, omission: '…', escape: false)) + " | #{site_hostname}" + +- 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') }/ + %link{ rel: 'alternate', type: 'application/activity+json', href: ActivityPub::TagManager.instance.uri_for(stream_entry.activity) }/ + + = opengraph 'og:site_name', site_title + = opengraph 'og:type', 'article' + = opengraph 'og:title', "#{display_name(account)} (@#{account.local_username_and_domain})" + = opengraph 'og:url', short_account_status_url(account, stream_entry.activity) + + = render 'stream_entries/og_description', activity: stream_entry.activity + = render 'stream_entries/og_image', activity: stream_entry.activity, account: account diff --git a/app/views/stream_entries/show.html.haml b/app/views/stream_entries/show.html.haml index 0e81c4f6..018cebf5 100644 --- a/app/views/stream_entries/show.html.haml +++ b/app/views/stream_entries/show.html.haml @@ -1,21 +1,4 @@ -- content_for :page_title do - = t('statuses.title', name: display_name(@account), quote: truncate(@stream_entry.activity.spoiler_text.presence || @stream_entry.activity.text, length: 50, omission: '…', escape: false)) - -- 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') }/ - %link{ rel: 'alternate', type: 'application/activity+json', href: ActivityPub::TagManager.instance.uri_for(@stream_entry.activity) }/ - - = opengraph 'og:site_name', site_title - = opengraph 'og:type', 'article' - = opengraph 'og:title', "#{display_name(@account)} (@#{@account.local_username_and_domain})" - = opengraph 'og:url', short_account_status_url(@account, @stream_entry.activity) - - = render 'stream_entries/og_description', activity: @stream_entry.activity - = render 'stream_entries/og_image', activity: @stream_entry.activity, account: @account += render 'stream_entries/meta', stream_entry: @stream_entry, account: @account .grid .column-0 diff --git a/app/views/tags/_meta.html.haml b/app/views/tags/_meta.html.haml new file mode 100644 index 00000000..072a2c45 --- /dev/null +++ b/app/views/tags/_meta.html.haml @@ -0,0 +1,10 @@ +- content_for :page_title do + = "##{@tag.name} - Hashtag | #{site_hostname}" + +- content_for :header_tags do + %meta{ name: 'robots', content: 'noindex' }/ + %link{ rel: 'alternate', type: 'application/rss+xml', href: tag_url(@tag, format: 'rss') }/ + + %script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json) + = javascript_pack_tag 'about', integrity: true, crossorigin: 'anonymous' + = render 'tags/og' diff --git a/app/views/tags/show.html.haml b/app/views/tags/show.html.haml index f4ee8103..8b37d229 100644 --- a/app/views/tags/show.html.haml +++ b/app/views/tags/show.html.haml @@ -1,13 +1,4 @@ -- content_for :page_title do - = "##{@tag.name}" - -- content_for :header_tags do - %meta{ name: 'robots', content: 'noindex' }/ - %link{ rel: 'alternate', type: 'application/rss+xml', href: tag_url(@tag, format: 'rss') }/ - - %script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json) - = javascript_pack_tag 'about', integrity: true, crossorigin: 'anonymous' - = render 'og' += render 'tags/meta', tag: @tag, initial_state_json: @initial_state_json .page-header %h1= "##{@tag.name}" diff --git a/config/routes.rb b/config/routes.rb index d360feb2..d3275443 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -446,6 +446,15 @@ Rails.application.routes.draw do get '/about/dmca', to: 'about#dmca' get '/about/sales', to: 'about#sales' + get '/tags/:tag', to: 'home#index' + get '/:username', to: 'home#index', as: :short_account + get '/:username/with_replies', to: 'home#index', as: :short_account_with_replies + get '/:username/media', to: 'home#index', as: :short_account_media + get '/:username/tagged/:tag', to: 'home#index', as: :short_account_tag + get '/:username/posts/:statusId/reblogs', to: 'home#index' + get '/:account_username/posts/:id', to: 'home#index', as: :short_account_status + get '/:account_username/posts/:id/embed', to: 'statuses#embed', as: :embed_short_account_status + get '/(*any)', to: 'home#index', as: :web root 'home#index' @@ -454,13 +463,6 @@ Rails.application.routes.draw do get '/explore', to: 'directories#index', as: :explore get '/explore/:id', to: 'directories#show', as: :explore_hashtag - get '/:username', to: 'accounts#show', as: :short_account - get '/:username/with_replies', to: 'accounts#show', as: :short_account_with_replies - get '/:username/media', to: 'accounts#show', as: :short_account_media - get '/:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag - get '/:account_username/posts/:id', to: 'statuses#show', as: :short_account_status - get '/:account_username/posts/:id/embed', to: 'statuses#embed', as: :embed_short_account_status - resources :tags, only: [:show] match '*unmatched_route',