Merge branch 'feature/adding_embed_and_meta_tags' of https://code.gab.com/gab/social/gab-social into develop
This commit is contained in:
commit
0ef81876dc
|
@ -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
|
||||
|
|
|
@ -194,7 +194,7 @@ class SwitchingColumnsArea extends React.PureComponent {
|
|||
<WrappedRoute path='/groups/:id/edit' page={GroupPage} component={GroupEdit} content={children} />
|
||||
<WrappedRoute path='/groups/:id' page={GroupPage} component={GroupTimeline} content={children} />
|
||||
|
||||
<WrappedRoute path='/tags/:id' component={HashtagTimeline} content={children} />
|
||||
<WrappedRoute path='/tags/:id' publicRoute component={HashtagTimeline} content={children} />
|
||||
|
||||
<WrappedRoute path='/lists' layout={LAYOUT.DEFAULT} component={Lists} content={children} />
|
||||
<WrappedRoute path='/list/:id' page={HomePage} component={ListTimeline} content={children} />
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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'
|
|
@ -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}"
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue