refactor newsletter script
This commit is contained in:
@@ -11,29 +11,34 @@ feed = Nokogiri::XML(
|
|||||||
post = feed.search("rss channel item").first
|
post = feed.search("rss channel item").first
|
||||||
title = post.search("title").text
|
title = post.search("title").text
|
||||||
url = post.search("link").text
|
url = post.search("link").text
|
||||||
|
body = post.search("description").text
|
||||||
|
|
||||||
body = %(<h1>#{title}</h1>
|
body = %(<h1>#{title}</h1>
|
||||||
<p>
|
<p>
|
||||||
By David Eisinger ·
|
By David Eisinger ·
|
||||||
<a href="#{url}">View original post</a>
|
<a href="#{url}">View original post</a>
|
||||||
</p>
|
</p>
|
||||||
#{post.search("description").text}
|
#{body})
|
||||||
)
|
|
||||||
|
# escape curly braces (they're important in listmonk)
|
||||||
|
body = body
|
||||||
.gsub("{", "{")
|
.gsub("{", "{")
|
||||||
.gsub("}", "}")
|
.gsub("}", "}")
|
||||||
.gsub(/width="(\d+)"/) do
|
|
||||||
%(width="#{$1.to_i/2}")
|
# half-size images
|
||||||
end
|
body = body
|
||||||
.gsub(/height="(\d+)"/) do
|
.gsub(/width="(\d+)"/) { %(width="#{$1.to_i/2}") }
|
||||||
%(height="#{$1.to_i/2}")
|
.gsub(/height="(\d+)"/) { %(height="#{$1.to_i/2}") }
|
||||||
end
|
|
||||||
.gsub(/<audio controls src="([^"]+)"><\/audio>/) do
|
# replace audio tags with links
|
||||||
|
body = body.gsub(/<audio controls src="([^"]+)"><\/audio>/) do
|
||||||
filename = $1.split("/").last
|
filename = $1.split("/").last
|
||||||
%(<a href="#{$1}">#{filename}</a>)
|
%(<a href="#{$1}">#{filename}</a>)
|
||||||
end
|
end
|
||||||
.gsub(/<a href="#fn[^>]+>(\d+)<\/a>/) do
|
|
||||||
$1
|
# remove footnote jump links
|
||||||
end
|
body = body
|
||||||
|
.gsub(/<a href="#fn[^>]+>(\d+)<\/a>/) { $1 }
|
||||||
.gsub(/ <a href="#fnref:[^>]+>↩︎<\/a>/, "")
|
.gsub(/ <a href="#fnref:[^>]+>↩︎<\/a>/, "")
|
||||||
|
|
||||||
p HTTParty.post(
|
p HTTParty.post(
|
||||||
|
|||||||
Reference in New Issue
Block a user