diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 2b1b9cc7..7f251434 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -274,56 +274,55 @@ def fetch_reddit_comments(id, sort_by = "confidence") end def template_youtube_comments(comments, locale, thin_mode) - html = "" - - root = comments["comments"].as_a - root.each do |child| - if child["replies"]? - replies_html = <<-END_HTML -
-
-
-

- #{translate(locale, "View `x` replies", child["replies"]["replyCount"].to_s)} -

+ String.build do |html| + root = comments["comments"].as_a + root.each do |child| + if child["replies"]? + replies_html = <<-END_HTML + -
- END_HTML - end - - if !thin_mode - author_thumbnail = "/ggpht#{URI.parse(child["authorThumbnails"][-1]["url"].as_s).full_path}" - else - author_thumbnail = "" - end - - html += <<-END_HTML -
-
- -
-
-

- - #{child["author"]} - -

#{child["contentHtml"]}

- #{translate(locale, "`x` ago", recode_date(Time.unix(child["published"].as_i64), locale))} #{child["isEdited"] == true ? translate(locale, "(edited)") : ""} - | - [YT] - | - #{number_with_separator(child["likeCount"])} - END_HTML - - if child["creatorHeart"]? - if !thin_mode - creator_thumbnail = "/ggpht#{URI.parse(child["creatorHeart"]["creatorThumbnail"].as_s).full_path}" - else - creator_thumbnail = "" + END_HTML end - html += <<-END_HTML + if !thin_mode + author_thumbnail = "/ggpht#{URI.parse(child["authorThumbnails"][-1]["url"].as_s).full_path}" + else + author_thumbnail = "" + end + + html << <<-END_HTML +
+
+ +
+
+

+ + #{child["author"]} + +

#{child["contentHtml"]}

+ #{translate(locale, "`x` ago", recode_date(Time.unix(child["published"].as_i64), locale))} #{child["isEdited"] == true ? translate(locale, "(edited)") : ""} + | + [YT] + | + #{number_with_separator(child["likeCount"])} + END_HTML + + if child["creatorHeart"]? + if !thin_mode + creator_thumbnail = "/ggpht#{URI.parse(child["creatorHeart"]["creatorThumbnail"].as_s).full_path}" + else + creator_thumbnail = "" + end + + html << <<-END_HTML
@@ -332,83 +331,77 @@ def template_youtube_comments(comments, locale, thin_mode)
+ END_HTML + end + + html << <<-END_HTML +

+ #{replies_html} +
+
END_HTML end - html += <<-END_HTML -

- #{replies_html} + if comments["continuation"]? + html << <<-END_HTML + -
- END_HTML + END_HTML + end end - - if comments["continuation"]? - html += <<-END_HTML -
- -
- END_HTML - end - - return html end def template_reddit_comments(root, locale) - html = "" - root.each do |child| - if child.data.is_a?(RedditComment) - child = child.data.as(RedditComment) - body_html = HTML.unescape(child.body_html) + String.build do |html| + root.each do |child| + if child.data.is_a?(RedditComment) + child = child.data.as(RedditComment) + body_html = HTML.unescape(child.body_html) - replies_html = "" - if child.replies.is_a?(RedditThing) - replies = child.replies.as(RedditThing) - replies_html = template_reddit_comments(replies.data.as(RedditListing).children, locale) - end + replies_html = "" + if child.replies.is_a?(RedditThing) + replies = child.replies.as(RedditThing) + replies_html = template_reddit_comments(replies.data.as(RedditListing).children, locale) + end - content = <<-END_HTML -

- [ - ] - #{child.author} - #{translate(locale, "`x` points", number_with_separator(child.score))} - #{translate(locale, "`x` ago", recode_date(child.created_utc, locale))} - #{translate(locale, "permalink")} -

-
- #{body_html} - #{replies_html} -
- END_HTML - - if child.depth > 0 - html += <<-END_HTML + if child.depth > 0 + html << <<-END_HTML
- #{content} -
-
- END_HTML - else - html += <<-END_HTML + END_HTML + else + html << <<-END_HTML
- #{content} -
-
+ END_HTML + end + + html << <<-END_HTML +

+ [ - ] + #{child.author} + #{translate(locale, "`x` points", number_with_separator(child.score))} + #{translate(locale, "`x` ago", recode_date(child.created_utc, locale))} + #{translate(locale, "permalink")} +

+
+ #{body_html} + #{replies_html} +
+
+ END_HTML end end end - - return html end def replace_links(html)