Skip to content

Commit 8bffd4e

Browse files
committed
Fixed structured data for comments and added interactionCount
1 parent 454085e commit 8bffd4e

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

app/helpers/protips_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def subscription_link(topic, additional_classes="", options={})
120120

121121
def upvote_link(protip, classname)
122122
if protip.already_voted?(current_user, current_user.try(:tracking_code), request.remote_ip)
123-
content_tag :div, "#{protip.upvotes}", class: "upvoted #{classname}"
123+
content_tag :div, "#{protip.upvotes}", class: "upvoted #{classname}", itemprop: 'interactionCount'
124124
else
125-
link_to "#{protip.upvotes}", upvote_protip_path(protip.public_id), class: "#{classname} track", remote: true, method: :post, rel: "nofollow", 'data-action' => "upvote protip", 'data-from' => (classname == "small-upvote" ? 'mini protip' : 'protip')
125+
link_to "#{protip.upvotes}", upvote_protip_path(protip.public_id), class: "#{classname} track", remote: true, method: :post, rel: "nofollow", 'data-action' => "upvote protip", 'data-from' => (classname == "small-upvote" ? 'mini protip' : 'protip'), itemprop: 'interactionCount'
126126
end
127127
end
128128

app/views/comments/_comment.html.haml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
%meta{itemprop: :alternateName, content: comment.user.username}
77
.comment-avatar
88
= image_tag(users_image_path(comment.user), class: 'avatar')
9-
%a.comment-user{href: profile_path(comment.user.username), 'data-reply-to' => comment.user.username, itemprop: 'creator'}
9+
%a.comment-user{href: profile_path(comment.user.username), 'data-reply-to' => comment.user.username, itemprop: 'author'}
1010
= comment.user.username
1111
%a.like{href:like_protip_comment_path(comment.commentable.try(:public_id), comment.id), 'data-remote' => 'true', 'data-method' => :post, class: comment_liked_class(comment), rel: "nofollow"}
1212
= comment_likes(comment)
1313
.comment{itemprop: :commentText}
1414
= raw sanitize(formatted_comment(comment.body))
15+
-# TODO: Rework the comment editing bar outside of the same element as the commentText
1516
- if can_edit_comment?(comment)
1617
.edit-comment.hidden
1718
= form_for [comment.commentable, comment] do |f|

app/views/protips/_protip.html.haml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
%article.tip-panel{ id: protip.public_id }
7272
= share_on_twitter(protip, 'share-this-tip direction')
73-
= upvote_link(protip, "upvote")
73+
= upvote_link(protip, 'upvote')
7474
%header.tip-header
7575
%h1.tip-title{itemprop: :headline}
7676
-if mode == 'popup'
@@ -92,7 +92,7 @@
9292
= link_to 'delete', delete_tag_protip_path(protip.public_id, CGI.escape(tag)), method: :post, class: "delete"
9393

9494
%div.timestamp.cf{ title: 'Publish time' }
95-
%i.fa.fa-clock-o
95+
%i.fa.fa-clock-o{ itemprop: 'datePublished' }
9696
= local_time_ago(protip.created_at)
9797

9898
- if is_admin?
@@ -109,7 +109,7 @@
109109
= raw sanitize(protip.to_html)
110110

111111
- if include_comments
112-
%section.comments{ itemscope: true, itemtype: 'https://schema.org/UserComments', class:('no-comments' if protip.comments.empty? ) }
112+
%section.comments{ class:('no-comments' if protip.comments.empty? ) }
113113
- if protip.comments.any?
114114
%h2.comments-header
115115
%i.fa.fa-comments

lib/cfm.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ def render(text)
1414
USERNAME_BLACKLIST = %w(include)
1515

1616
private
17+
1718
def render_cfm(text)
18-
text.lines.map { |x| inspect_line x }.join("")
19+
text.lines.map do |x|
20+
inspect_line(x)
21+
end.join('')
1922
end
2023

2124
def coderwall_user_link(username)
@@ -24,7 +27,11 @@ def coderwall_user_link(username)
2427

2528
def inspect_line(line)
2629
#hotlink coderwall usernames to their profile, but don't search for @mentions in code blocks
27-
line.start_with?(" ") ? line : line.gsub(/((?<!\s{4}).*)@([a-zA-Z_\-0-9]+)/) { $1+coderwall_user_link($2) }
30+
if line.start_with?(' ')
31+
line
32+
else
33+
line.gsub(/((?<!\s{4}).*)@([a-zA-Z_\-0-9]+)/) { $1+coderwall_user_link($2) }
34+
end
2835
end
2936
end
3037
end

0 commit comments

Comments
 (0)