Update RssReader's liquid & youtube parsing logic (#3229)
* Loosen up Liquid::Variable * Improve RssReader's youtube id detection * Revert "Loosen up Liquid::Variable" This reverts commit fd385c6649a9e0ca3786588a29a3ff2b8fe98218. * RSS: Wrap liquid variable in backtick * User inner_html intead of text
This commit is contained in:
parent
de2bf910fd
commit
8ec4e338ed
1 changed files with 20 additions and 3 deletions
|
|
@ -37,9 +37,17 @@ class RssReader
|
|||
def assemble_body_markdown
|
||||
cleaned_content = HtmlCleaner.new.clean_html(get_content)
|
||||
cleaned_content = thorough_parsing(cleaned_content, @feed.url)
|
||||
ReverseMarkdown.
|
||||
|
||||
content = ReverseMarkdown.
|
||||
convert(cleaned_content, github_flavored: true).
|
||||
gsub("```\n\n```", "").gsub(/ |\u00A0/, " ")
|
||||
gsub("```\n\n```", "").
|
||||
gsub(/ |\u00A0/, " ")
|
||||
|
||||
content.gsub!(/{%\syoutube\s(.{11,18})\s%}/) do |tag|
|
||||
tag.gsub("\\_", "_")
|
||||
end
|
||||
|
||||
content
|
||||
end
|
||||
|
||||
def get_content
|
||||
|
|
@ -53,6 +61,7 @@ class RssReader
|
|||
parse_and_translate_gist_iframe!(html_doc)
|
||||
parse_and_translate_youtube_iframe!(html_doc)
|
||||
parse_and_translate_tweet!(html_doc)
|
||||
parse_liquid_variable!(html_doc)
|
||||
else
|
||||
clean_relative_path!(html_doc, feed_url)
|
||||
end
|
||||
|
|
@ -93,11 +102,19 @@ class RssReader
|
|||
end
|
||||
end
|
||||
|
||||
def parse_liquid_variable!(html_doc)
|
||||
# Medium articles does not wrap {{ }} content in liquid tag.
|
||||
# This will wrap do so for content that isn't in pre and code tag
|
||||
html_doc.css("//body :not(pre):not(code)").each do |node|
|
||||
node.inner_html = node.inner_html.gsub(/{{.*?}}/) { |liquid| "`#{liquid}`" }
|
||||
end
|
||||
end
|
||||
|
||||
def parse_and_translate_youtube_iframe!(html_doc)
|
||||
html_doc.css("iframe").each do |iframe|
|
||||
if /youtube\.com/.match?(iframe.attributes["src"].value)
|
||||
iframe.name = "p"
|
||||
youtube_id = iframe.attributes["src"].value.scan(/embed%2F(.{4,12})%3F/).flatten.first
|
||||
youtube_id = iframe.attributes["src"].value.scan(/embed%2F(.{4,11})/).flatten.first
|
||||
iframe.keys.each { |attr| iframe.remove_attribute(attr) }
|
||||
iframe.inner_html = "{% youtube #{youtube_id} %}"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue