From 8ac59b33368c2e30c4e53d665e00508cff9d69f8 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:13:56 -0400 Subject: [PATCH 01/13] Added a new file for tags view meta content --- app/views/tags/_meta.html.haml | 10 ++++++++++ app/views/tags/show.html.haml | 11 +---------- 2 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 app/views/tags/_meta.html.haml 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}" From a7185dc9cab7b870f11ea1894182134e44d11919 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:14:24 -0400 Subject: [PATCH 02/13] Added a new file for stream_entries view meta content --- app/views/stream_entries/_meta.html.haml | 18 ++++++++++++++++++ app/views/stream_entries/show.html.haml | 19 +------------------ 2 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 app/views/stream_entries/_meta.html.haml 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 From e576c2c3d701218a99a4f2505a254540ca96e9c1 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:14:41 -0400 Subject: [PATCH 03/13] Added a new file for account view meta content --- app/views/accounts/_meta.html.haml | 21 +++++++++++++++++++++ app/views/accounts/show.html.haml | 23 +---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 app/views/accounts/_meta.html.haml 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 From 57b37e0555d7df537ec3aa0990b291c6a8747c88 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:15:02 -0400 Subject: [PATCH 04/13] Updated stream_entries view detailed_status "open in web" link --- app/views/stream_entries/_detailed_status.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' From 4b1c4c31d1dd9d0f61e5e11ed94ff3a756a01fd3 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:15:30 -0400 Subject: [PATCH 05/13] Upated /tags/:id in react app to be a public route --- app/javascript/gabsocial/features/ui/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/gabsocial/features/ui/index.js b/app/javascript/gabsocial/features/ui/index.js index 43c18ede..b4c28f58 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 { - + From dcb05727ee0366910b9884d55a75bdac63a32fb2 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:20:18 -0400 Subject: [PATCH 06/13] Updated routes.rb account and status routes all are now pointed at home#index because its all within the react app and not the ssr haml pages embeding statuses route still is pointed at statuses#embed as it is still a part of the ssr page --- config/routes.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index d360feb2..20a135b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -446,6 +446,14 @@ Rails.application.routes.draw do get '/about/dmca', to: 'about#dmca' get '/about/sales', to: 'about#sales' + 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 +462,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', From 2c9bcc0c2bc8b8bf064801cdf3bee3c00c9ac566 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:20:36 -0400 Subject: [PATCH 07/13] Added tags route to routes.rb and point to home#index --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index 20a135b5..d3275443 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -446,6 +446,7 @@ 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 From 499bf9eb69a6a86bd3bf8381624e489472202b8b Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:21:33 -0400 Subject: [PATCH 08/13] Updated status_finder to check for home#index for updated status route check previous commit: dcb0572 this enables status embeding to work fully --- app/lib/status_finder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 5b27b6b646214ed7763f41a9eddd5bc7fff6ab8e Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:22:27 -0400 Subject: [PATCH 09/13] Updated home_controller.rb to check for meta data for accounts, statuses, tags if route is account/profile page, status page or tags page, set data to send to application.html.haml to render meta tag content --- app/controllers/home_controller.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index b498a1ed..64de0d20 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,6 +12,25 @@ class HomeController < ApplicationController private + def set_data_for_meta + 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? + @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? From 1e6cf79f9e8a09bec7c566a970b9be89ea93bf9f Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 01:23:21 -0400 Subject: [PATCH 10/13] Added checks in application.html.haml for tag, status, account for meta tags enables meta tag content for search engine indexing and titles per each --- app/views/layouts/application.html.haml | 7 +++++++ 1 file changed, 7 insertions(+) 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' From 5750786d1ab180caa22bd2861e82959b621e3a67 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 17 Aug 2019 12:16:15 -0400 Subject: [PATCH 11/13] Removed bang operator from account, tag finders in home_controller If account or tag does not exist, it tosses an error. without bang it ignores if doesn't exist. --- app/controllers/home_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 64de0d20..242f5efd 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -14,9 +14,9 @@ class HomeController < ApplicationController def set_data_for_meta if params[:username].present? - @account = Account.find_local!(params[:username]) + @account = Account.find_local(params[:username]) elsif params[:account_username].present? - @account = Account.find_local!(params[:account_username]) + @account = Account.find_local(params[:account_username]) if params[:id].present? @status = @account.statuses.find(params[:id]) @@ -26,7 +26,7 @@ class HomeController < ApplicationController end if request.path.starts_with?('/tags') && params[:tag].present? - @tag = Tag.find_normalized!(params[:tag]) + @tag = Tag.find_normalized(params[:tag]) end end From d084b8d5f99401576bd5338a5a7b3d8edf5838e7 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sun, 18 Aug 2019 00:09:25 -0400 Subject: [PATCH 12/13] Updated route matches in home_controller Added in set_data_for_meta too --- app/controllers/home_controller.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 242f5efd..bc2e53fd 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -13,6 +13,8 @@ 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? @@ -35,13 +37,15 @@ class HomeController < ApplicationController 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 From d3501953f49c7ce110cbb21da5a8f57788fa29fe Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sun, 18 Aug 2019 00:11:41 -0400 Subject: [PATCH 13/13] Added check for account variable exists in home_controller meta function --- app/controllers/home_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index bc2e53fd..3cdc9fb9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -20,7 +20,7 @@ class HomeController < ApplicationController elsif params[:account_username].present? @account = Account.find_local(params[:account_username]) - if params[:id].present? + if params[:id].present? && !@account.nil? @status = @account.statuses.find(params[:id]) @stream_entry = @status.stream_entry @type = @stream_entry.activity_type.downcase