mirror of
https://github.com/iv-org/invidious.git
synced 2024-06-07 19:40:52 +00:00
Add comment formatting
This commit is contained in:
parent
917d220623
commit
b3f9059452
@ -1813,9 +1813,38 @@ get "/api/v1/comments/:id" do |env|
|
|||||||
node_comment = node["commentRenderer"]
|
node_comment = node["commentRenderer"]
|
||||||
end
|
end
|
||||||
|
|
||||||
content_text = node_comment["contentText"]["simpleText"]?.try &.as_s.rchop('\ufeff')
|
contentHtml = node_comment["contentText"]["simpleText"]?.try &.as_s.rchop('\ufeff')
|
||||||
content_text ||= node_comment["contentText"]["runs"].as_a.map { |comment| comment["text"] }
|
contentHtml ||= node_comment["contentText"]["runs"].as_a.map do |run|
|
||||||
.join("").rchop('\ufeff')
|
text = run["text"].as_s
|
||||||
|
|
||||||
|
if run["text"] == "\n"
|
||||||
|
text = "<br>"
|
||||||
|
end
|
||||||
|
|
||||||
|
if run["bold"]?
|
||||||
|
text = "<b>#{text}</b>"
|
||||||
|
end
|
||||||
|
|
||||||
|
if run["italics"]?
|
||||||
|
text = "<i>#{text}</i>"
|
||||||
|
end
|
||||||
|
|
||||||
|
if run["navigationEndpoint"]?
|
||||||
|
url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s
|
||||||
|
if url
|
||||||
|
url = URI.parse(url)
|
||||||
|
url = HTTP::Params.parse(url.query.not_nil!)["q"]
|
||||||
|
else
|
||||||
|
url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
|
||||||
|
end
|
||||||
|
|
||||||
|
text = %(<a href="#{url}">#{text}</a>)
|
||||||
|
end
|
||||||
|
|
||||||
|
text
|
||||||
|
end.join.rchop('\ufeff')
|
||||||
|
|
||||||
|
content, contentHtml = html_to_description(contentHtml)
|
||||||
|
|
||||||
author = node_comment["authorText"]?.try &.["simpleText"]
|
author = node_comment["authorText"]?.try &.["simpleText"]
|
||||||
author ||= ""
|
author ||= ""
|
||||||
@ -1843,7 +1872,8 @@ get "/api/v1/comments/:id" do |env|
|
|||||||
|
|
||||||
published = decode_date(node_comment["publishedTimeText"]["runs"][0]["text"].as_s.rchop(" (edited)"))
|
published = decode_date(node_comment["publishedTimeText"]["runs"][0]["text"].as_s.rchop(" (edited)"))
|
||||||
|
|
||||||
json.field "content", content_text
|
json.field "content", content
|
||||||
|
json.field "contentHtml", contentHtml
|
||||||
json.field "published", published.epoch
|
json.field "published", published.epoch
|
||||||
json.field "likeCount", node_comment["likeCount"]
|
json.field "likeCount", node_comment["likeCount"]
|
||||||
json.field "commentId", node_comment["commentId"]
|
json.field "commentId", node_comment["commentId"]
|
||||||
|
@ -113,7 +113,7 @@ def template_youtube_comments(comments)
|
|||||||
- #{recode_date(Time.epoch(child["published"].as_i64))} ago
|
- #{recode_date(Time.epoch(child["published"].as_i64))} ago
|
||||||
</p>
|
</p>
|
||||||
<div>
|
<div>
|
||||||
#{child["content"]}
|
<p style="white-space:pre-wrap">#{child["contentHtml"]}</p>
|
||||||
#{replies_html}
|
#{replies_html}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user