]> cat aescling's git repositories - mastodon.git/commitdiff
significant improvement in microformats markup (#1063)
authorBen Roberts <ben@thatmustbe.me>
Wed, 12 Apr 2017 18:04:33 +0000 (14:04 -0400)
committerEugen <eugen@zeonfederated.com>
Wed, 12 Apr 2017 18:04:33 +0000 (20:04 +0200)
* 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

app/helpers/stream_entries_helper.rb
app/lib/formatter.rb
app/views/accounts/_header.html.haml
app/views/stream_entries/_detailed_status.html.haml
app/views/stream_entries/_simple_status.html.haml
app/views/stream_entries/_status.html.haml
app/views/stream_entries/show.html.haml

index 18ef8b909f5ac850e2cb0ee1446beeef761a65a3..00a01df44d60af49bc202560d48f36953e013603 100644 (file)
@@ -13,15 +13,29 @@ module StreamEntriesHelper
     "@#{account.acct}#{embedded_view? && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}"
   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-reblog u-repost-of h-cite' if status.reblog?
-    classes << 'entry-predecessor u-in-reply-to h-cite' if is_predecessor
-    classes << 'entry-successor u-comment h-cite' if is_successor
-    classes << 'entry-center h-entry' if include_threads
+    classes << 'entry-predecessor' if is_predecessor
+    classes << 'entry-reblog' if status.reblog?
+    classes << 'entry-successor' if is_successor
+    classes << 'entry-center' if include_threads
     classes.join(' ')
   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)
     return false if text.empty?
 
index c3f331ff7d0ce1cf625e37cfa4333ad8d77fa397..b6d371ed2d6a14fa8b8087dd2f7c1a6a02df4f50 100644 (file)
@@ -95,6 +95,6 @@ class Formatter
   end
 
   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
index 0d43fba304967fb8443f94324e232db870cea5e3..beee96cd8d773ae66118cd42160d50c869d2576d 100644 (file)
@@ -13,7 +13,7 @@
   %h1.name
     %span.p-name.emojify= display_name(@account)
     %small
-      %span.p-nickname= "@#{@account.username}"
+      %span= "@#{@account.username}"
       = fa_icon('lock') if @account.locked?
   .details
     .bio
index 466e0dd5ae151059b3e6ae71d467a0db6fed865b..e3cc522be20245cac422c1e10af4fe4a73ce66b6 100644 (file)
@@ -5,14 +5,15 @@
         = image_tag status.account.avatar.url(:original), width: 48, height: 48, alt: '', class: 'u-photo'
     %span.display-name
       %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?
       %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')
-    %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?
     - if status.media_attachments.first.video?
index a758d5ccdfbe04b59f3610e0458afdbc10f893f7..52905ff5e0aa15c282c948f1ba8a674f99e84fd4 100644 (file)
           = image_tag status.account.avatar(:original), width: 48, height: 48, alt: '', class: 'u-photo'
       %span.display-name
         %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?
       %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')
-    %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?
     .status__attachments
index 1333d4d82a5f4334beb1b412af52341054d32e7b..f389a8dfe71ef9d4f3ddab42c745e0de86605d36 100644 (file)
@@ -1,12 +1,22 @@
 - include_threads ||= false
 - is_predecessor  ||= 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
+- 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
-  = 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?
     .pre-header
       %div.pre-header__icon
@@ -19,4 +29,4 @@
   = render partial: centered ? 'stream_entries/detailed_status' : 'stream_entries/simple_status', locals: { status: status.proper }
 
 - 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}
index 088881b11f6dab89d8a62e590b80681264924e3c..f37fb79196c29037536f395b45e3212712c4b611 100644 (file)
@@ -23,5 +23,5 @@
 - if !user_signed_in? && !Rails.configuration.x.single_user_mode
   = 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 }