Fixed issue with showing status meta in html head/title tags

• Fixed:
- issue with showing status meta in html head/title tags
This commit is contained in:
mgabdev 2020-12-23 17:38:18 -05:00
parent 19a9435203
commit aa88fc16c9
6 changed files with 60 additions and 16 deletions

View File

@ -1,10 +1,18 @@
# frozen_string_literal: true # frozen_string_literal: true
class ReactController < ApplicationController class ReactController < ApplicationController
include Authorization
before_action :authenticate_user!, only: [:react, :home] before_action :authenticate_user!, only: [:react, :home]
before_action :set_referrer_policy_header, only: [:react, :home]
before_action :set_initial_state_json, only: [:react, :home] before_action :set_account, only: [:status_embed, :status_show, :account_show]
before_action :set_data_for_meta, only: [:react, :home] before_action :set_status, only: [:status_embed, :status_show]
before_action :check_account_suspension, only: [:status_embed, :status_show, :account_show]
before_action :redirect_to_original, only: [:status_show]
before_action :set_referrer_policy_header, only: [:react, :home, :status_embed, :status_show, :account_show]
before_action :set_initial_state_json, only: [:react, :home, :status_embed, :status_show, :account_show]
before_action :set_data_for_meta, only: [:react, :home, :status_embed, :status_show, :account_show]
before_action :set_instance_presenter before_action :set_instance_presenter
@ -21,8 +29,43 @@ class ReactController < ApplicationController
return not_found return not_found
end end
def status_show
return process(:react)
end
def status_embed
# : todo :
end
def account_show
# : todo :
end
private private
def set_account
@account = Account.find_acct!(params[:username])
end
def set_status
@status = @account.statuses.find(params[:statusId])
authorize @status, :show?
rescue GabSocial::NotPermittedError
# Reraise in order to get a 404
raise ActiveRecord::RecordNotFound
end
def check_account_suspension
gone if @account.suspended?
end
def redirect_to_original
if @status.reblog?
redirect_to ::TagManager.instance.url_for(@status.reblog)
end
end
def set_data_for_meta def set_data_for_meta
return if find_route_matches && current_account return if find_route_matches && current_account
@ -78,6 +121,9 @@ class ReactController < ApplicationController
end end
def set_referrer_policy_header def set_referrer_policy_header
unless @status.nil?
return if @status.public_visibility? || @status.unlisted_visibility?
end
response.headers['Referrer-Policy'] = 'origin' response.headers['Referrer-Policy'] = 'origin'
end end

View File

@ -21,8 +21,7 @@ module AccountFinderConcern
end end
def find_acct(acct) def find_acct(acct)
username, domain = acct.split("@") find_now(acct)
find_now(username)
end end
def find_now(username) def find_now(username)

View File

@ -1,4 +1,4 @@
- the_title = t('statuses.title', name: display_name(account), quote: truncate(status.spoiler_text.presence || stream_entry.activity.text, length: 50, omission: '…', escape: false)) - the_title = t('statuses.title', name: display_name(account), quote: truncate(status.spoiler_text.presence, length: 50, omission: '…', escape: false))
- content_for :page_title do - content_for :page_title do
= the_title = the_title

View File

@ -1,4 +1,4 @@
- description = t('statuses.title', name: display_name(account), quote: activity.spoiler_text.presence || activity.text) - description = t('statuses.title', name: display_name(account), quote: status.spoiler_text.presence || status.text)
%meta{ name: 'description', content: description }/ %meta{ name: 'description', content: description }/
= opengraph 'og:description', description = opengraph 'og:description', description

View File

@ -1,6 +1,6 @@
- if activity.is_a?(Status) && (activity.non_sensitive_with_media? || (activity.with_media? && Setting.preview_sensitive_media)) - if status.is_a?(Status) && (status.non_sensitive_with_media? || (status.with_media? && Setting.preview_sensitive_media))
- player_card = false - player_card = false
- activity.media_attachments.each do |media| - status.media_attachments.each do |media|
- if media.image? - if media.image?
= opengraph 'og:image', full_asset_url(media.file.url(:original)) = opengraph 'og:image', full_asset_url(media.file.url(:original))
= opengraph 'og:image:type', media.file_content_type = opengraph 'og:image:type', media.file_content_type

View File

@ -400,19 +400,18 @@ Rails.application.routes.draw do
end end
end end
get '/g/:groupSlug', to: 'react#groupBySlug' get '/g/:groupSlug', to: 'react#groupBySlug'
get '/:username/posts/:statusId', to: 'react#status_show', username: username_regex
get '/:username/posts/:statusId', to: 'react#status_show', username: username_regex, as: :short_account_status
get '/:username/posts/:statusId/embed', to: 'react#embed_status', username: username_regex, as: :embed_short_account_status
get '/(*any)', to: 'react#react', as: :web get '/(*any)', to: 'react#react', as: :web
get '/:username', to: 'react#account_show', username: username_regex, as: :short_account_with_replies
root 'react#react' root 'react#react'
get '/', to: 'react#react', as: :homepage get '/', to: 'react#react', as: :homepage
get '/:username', to: 'accounts#show', username: username_regex, as: :short_account_with_replies
get '/:username/comments', to: 'accounts#show', username: username_regex, as: :short_account_comments_only
get '/:username/photos', to: 'accounts#show', username: username_regex, as: :short_account_media
get '/:username/posts/:statusId', to: 'statuses#show', username: username_regex
get '/:account_username/posts/:id', to: 'statuses#show', account_username: username_regex, as: :short_account_status
get '/:account_username/posts/:id/embed', to: 'statuses#embed', account_username: username_regex, as: :embed_short_account_status
get '/about', to: 'react#react' get '/about', to: 'react#react'
get '/about/tos', to: 'react#react' get '/about/tos', to: 'react#react'
get '/about/privacy', to: 'react#react' get '/about/privacy', to: 'react#react'