significant improvement in microformats markup (#1063)

* significant improvement in microformats markup

This is a huge improvement and I believe will close #965.

Had these microformats reviewed by others in the community to help
ensure they are at least correct, if not complete.

I did not want to change the structure of the page, and so there it does
not fully mark up the entire ancestry chain, or reply chain, only the
direct decendants and direct ancestors are correctly associated, but
this is likely fine as the most important bit is to have access to the
urls for those toots which are now correctly fetchable.

* improve code climate

* trying to pass code climate tests

* code climate

* fix p-summary for content warning posts

* fix error introduced when merging via github
This commit is contained in:
Ben Roberts 2017-04-12 14:04:33 -04:00 committed by Eugen
parent e32edd247f
commit 0254ee9795
7 changed files with 44 additions and 19 deletions

View file

@ -13,15 +13,29 @@ module StreamEntriesHelper
"@#{account.acct}#{embedded_view? && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}" "@#{account.acct}#{embedded_view? && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}"
end end
def entry_classes(status, is_predecessor, is_successor, include_threads) def style_classes(status, is_predecessor, is_successor, include_threads)
classes = ['entry'] classes = ['entry']
classes << 'entry-reblog u-repost-of h-cite' if status.reblog? classes << 'entry-predecessor' if is_predecessor
classes << 'entry-predecessor u-in-reply-to h-cite' if is_predecessor classes << 'entry-reblog' if status.reblog?
classes << 'entry-successor u-comment h-cite' if is_successor classes << 'entry-successor' if is_successor
classes << 'entry-center h-entry' if include_threads classes << 'entry-center' if include_threads
classes.join(' ') classes.join(' ')
end end
def microformats_classes(status, is_direct_parent, is_direct_child)
classes = []
classes << 'p-in-reply-to' if is_direct_parent
classes << 'p-repost-of' if status.reblog? && is_direct_parent
classes << 'p-comment' if is_direct_child
classes.join(' ')
end
def microformats_h_class(status, is_predecessor, is_successor, include_threads)
return 'h-cite' if is_predecessor || status.reblog || is_successor
return 'h-entry' unless include_threads
''
end
def rtl?(text) def rtl?(text)
return false if text.empty? return false if text.empty?

View file

@ -95,6 +95,6 @@ class Formatter
end end
def mention_html(match, account) def mention_html(match, account)
"#{match.split('@').first}<a href=\"#{TagManager.instance.url_for(account)}\" class=\"h-card u-url p-nickname mention\">@<span>#{account.username}</span></a>" "#{match.split('@').first}<span class=\"h-card\"><a href=\"#{TagManager.instance.url_for(account)}\" class=\"u-url mention\">@#{account.username}</a></span>"
end end
end end

View file

@ -13,7 +13,7 @@
%h1.name %h1.name
%span.p-name.emojify= display_name(@account) %span.p-name.emojify= display_name(@account)
%small %small
%span.p-nickname= "@#{@account.username}" %span= "@#{@account.username}"
= fa_icon('lock') if @account.locked? = fa_icon('lock') if @account.locked?
.details .details
.bio .bio

View file

@ -5,14 +5,15 @@
= image_tag status.account.avatar.url(:original), width: 48, height: 48, alt: '', class: 'u-photo' = image_tag status.account.avatar.url(:original), width: 48, height: 48, alt: '', class: 'u-photo'
%span.display-name %span.display-name
%strong.p-name.emojify= display_name(status.account) %strong.p-name.emojify= display_name(status.account)
%span.p-nickname= acct(status.account) %span= acct(status.account)
.status__content.e-content.p-name.emojify< .status__content.p-name.emojify<
- if status.spoiler_text? - if status.spoiler_text?
%p{ style: 'margin-bottom: 0' }< %p{ style: 'margin-bottom: 0' }<
%span>= "#{status.spoiler_text} " %span.p-summary>= "#{status.spoiler_text} "
%a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more') %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
%div{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status) %div.e-content{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
- unless status.media_attachments.empty? - unless status.media_attachments.empty?
- if status.media_attachments.first.video? - if status.media_attachments.first.video?

View file

@ -10,14 +10,14 @@
= image_tag status.account.avatar(:original), width: 48, height: 48, alt: '', class: 'u-photo' = image_tag status.account.avatar(:original), width: 48, height: 48, alt: '', class: 'u-photo'
%span.display-name %span.display-name
%strong.p-name.emojify= display_name(status.account) %strong.p-name.emojify= display_name(status.account)
%span.p-nickname= acct(status.account) %span= acct(status.account)
.status__content.e-content.p-name.emojify< .status__content.p-name.emojify<
- if status.spoiler_text? - if status.spoiler_text?
%p{ style: 'margin-bottom: 0' }< %p{ style: 'margin-bottom: 0' }<
%span>= "#{status.spoiler_text} " %span.p-summary>= "#{status.spoiler_text} "
%a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more') %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
%div{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status) %div.e-content{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
- unless status.media_attachments.empty? - unless status.media_attachments.empty?
.status__attachments .status__attachments

View file

@ -1,12 +1,22 @@
- include_threads ||= false - include_threads ||= false
- is_predecessor ||= false - is_predecessor ||= false
- is_successor ||= false - is_successor ||= false
- direct_reply_id ||= false
- parent_id ||= false
- is_direct_parent = direct_reply_id == status.id
- is_direct_child = parent_id == status.in_reply_to_id
- parent_id ||= false
- centered ||= include_threads && !is_predecessor && !is_successor - centered ||= include_threads && !is_predecessor && !is_successor
- h_class = microformats_h_class(status, is_predecessor, is_successor, include_threads)
- style_classes = style_classes(status, is_predecessor, is_successor, include_threads)
- mf_classes = microformats_classes(status, is_direct_parent, is_direct_child)
- entry_classes = h_class + ' ' + mf_classes + ' ' + style_classes
- if status.reply? && include_threads - if status.reply? && include_threads
= render partial: 'stream_entries/status', collection: @ancestors, as: :status, locals: { is_predecessor: true } = render partial: 'stream_entries/status', collection: @ancestors, as: :status, locals: { is_predecessor: true, direct_reply_id: status.in_reply_to_id}
.entry{ class: entry_classes }
.entry{ class: entry_classes(status, is_predecessor, is_successor, include_threads) }
- if status.reblog? - if status.reblog?
.pre-header .pre-header
%div.pre-header__icon %div.pre-header__icon
@ -19,4 +29,4 @@
= render partial: centered ? 'stream_entries/detailed_status' : 'stream_entries/simple_status', locals: { status: status.proper } = render partial: centered ? 'stream_entries/detailed_status' : 'stream_entries/simple_status', locals: { status: status.proper }
- if include_threads - if include_threads
= render partial: 'stream_entries/status', collection: @descendants, as: :status, locals: { is_successor: true } = render partial: 'stream_entries/status', collection: @descendants, as: :status, locals: { is_successor: true, parent_id: status.id}

View file

@ -23,5 +23,5 @@
- if !user_signed_in? && !Rails.configuration.x.single_user_mode - if !user_signed_in? && !Rails.configuration.x.single_user_mode
= render partial: 'shared/landing_strip', locals: { account: @stream_entry.account } = render partial: 'shared/landing_strip', locals: { account: @stream_entry.account }
.activity-stream.activity-stream-headless .activity-stream.activity-stream-headless.h-entry
= render partial: "stream_entries/#{@type}", locals: { @type.to_sym => @stream_entry.activity, include_threads: true } = render partial: "stream_entries/#{@type}", locals: { @type.to_sym => @stream_entry.activity, include_threads: true }