mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-18 21:03:27 +00:00
Simplify the og:image and og:description code in stream_entries/show (#1934)
This commit is contained in:
parent
7efde22c3a
commit
73b0af5c93
|
@ -110,6 +110,10 @@ class Status < ApplicationRecord
|
|||
results
|
||||
end
|
||||
|
||||
def non_sensitive_with_media?
|
||||
!sensitive? && media_attachments.any?
|
||||
end
|
||||
|
||||
class << self
|
||||
def as_home_timeline(account)
|
||||
where(account: [account] + account.following)
|
||||
|
|
4
app/views/stream_entries/_og_description.html.haml
Normal file
4
app/views/stream_entries/_og_description.html.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
- if activity.is_a?(Status) && activity.spoiler_text?
|
||||
%meta{ property: 'og:description', content: activity.spoiler_text }/
|
||||
- else
|
||||
%meta{ property: 'og:description', content: activity.content }/
|
6
app/views/stream_entries/_og_image.html.haml
Normal file
6
app/views/stream_entries/_og_image.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- if activity.is_a?(Status) && activity.non_sensitive_with_media?
|
||||
%meta{ property: 'og:image', content: full_asset_url(activity.media_attachments.first.file.url(:small)) }/
|
||||
- else
|
||||
%meta{ property: 'og:image', content: full_asset_url(account.avatar.url(:original)) }/
|
||||
%meta{ property: 'og:image:width', content: '120' }/
|
||||
%meta{ property: 'og:image:height', content: '120' }/
|
|
@ -6,17 +6,8 @@
|
|||
%meta{ property: 'og:type', content: 'article' }/
|
||||
%meta{ property: 'og:title', content: "#{@account.username} on #{Rails.configuration.x.local_domain}" }/
|
||||
|
||||
- if @stream_entry.activity.is_a?(Status) && !@stream_entry.activity.spoiler_text.blank?
|
||||
%meta{ property: 'og:description', content: @stream_entry.activity.spoiler_text }/
|
||||
- else
|
||||
%meta{ property: 'og:description', content: @stream_entry.activity.content }/
|
||||
|
||||
- if @stream_entry.activity.is_a?(Status) && !@stream_entry.activity.sensitive? && @stream_entry.activity.media_attachments.size > 0
|
||||
%meta{ property: 'og:image', content: full_asset_url(@stream_entry.activity.media_attachments.first.file.url(:small)) }/
|
||||
- else
|
||||
%meta{ property: 'og:image', content: full_asset_url(@account.avatar.url(:original)) }/
|
||||
%meta{ property: 'og:image:width', content: '120' }/
|
||||
%meta{ property: 'og:image:height', content: '120' }/
|
||||
= render 'stream_entries/og_description', activity: @stream_entry.activity
|
||||
= render 'stream_entries/og_image', activity: @stream_entry.activity, account: @account
|
||||
|
||||
%meta{ property: 'twitter:card', content: 'summary' }/
|
||||
|
||||
|
|
Loading…
Reference in a new issue