[rzz] create feed from the webpage instead

pull/30/head
Alpha Chen 5 years ago
parent 036dbe2f2f
commit fa09f59de0

@ -8,36 +8,32 @@ module Rzz
class App < Roda class App < Roda
plugin :caching plugin :caching
plugin :json
route do |r| route do |r|
r.get do r.get do
r.is "test-gym" do r.is "test-gym" do
url = "https://elemental.medium.com/feed" url = "https://elemental.medium.com/test-gym/home"
xml = URI.open(url).read html = URI.open(url).read
r.etag Digest::SHA1.hexdigest(xml)
doc = Nokogiri::HTML(html)
doc = Nokogiri::XML(xml) items = doc.xpath("//a[@data-post-id]").map {|a|
attrs = a.attributes
self_url = "#{r.base_url}#{r.path}" # Should this be configured via the environment? id = attrs.fetch("data-post-id").value
doc.at_xpath("/rss/channel/link/text()").content = self_url title = a.xpath("./h3").text
doc.at_xpath("/rss/channel/atom:link[@href='#{url}']")["href"] = self_url content = a.xpath("./div").text
href = URI(attrs.fetch("href"))
doc.at_xpath("/rss/channel/atom:link[@rel='hub']").remove url = "#{href.scheme}://#{href.host}#{href.path}"
{ id: id, title: title, content_text: content, url: url }
doc }
.xpath("/rss/channel/item")
.select {|item| item.xpath("./category[text()='test-gym']").empty? } {
.each(&:remove) version: "https://jsonfeed.org/version/1",
title: "Test Gym",
doc home_page_url: url,
.xpath("/rss/channel/item") feed_url: "#{r.base_url}#{r.path}",
.each do |item| items: items,
link = item.at_xpath("./link/text()").content }
item.at_xpath("./description/text()").content = URI.open(link).read
end
response.headers["Content-Type"] = "text/xml"
doc.to_xml
end end
end end
end end

Loading…
Cancel
Save