Skip to content

Instantly share code, notes, and snippets.

@jcouyang
Last active February 23, 2020 03:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcouyang/fb83001937006a830a810f83a1ba563e to your computer and use it in GitHub Desktop.
Save jcouyang/fb83001937006a830a810f83a1ba563e to your computer and use it in GitHub Desktop.
my blog comments
require "httparty"
require 'json'
url = "https://hypothes.is/api/search?wildcard_uri=https://blog.oyanglul.us/*&sort=created"
HEADER = <<-EOXML
<?xml version="1.0"?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Hypothesis Stream</title>
<link>https://hypothes.is/stream</link>
<atom:link href="https://hypothes.is/stream.rss" rel="self" type="application/rss+xml" />
<description>The Web. Annotated</description>
<pubDate>Wed, 07 Nov 2018 06:54:59 -0000</pubDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
EOXML
FOOTER = <<-EOXML
</channel>
</rss>
EOXML
resp = HTTParty.get(url)
items = JSON.parse(resp.body, symbolize_names: true)[:rows].map do |item|
%Q{
<item>
<title><![CDATA[#{item.dig(:document, :title, 0) || item[:text][0..20]}]]></title>
<description><![CDATA[#{item[:text]}]]></description>
<pubDate>#{item[:created]}</pubDate>
<guid isPermaLink="false">#{item[:id]}</guid>
<link>#{item[:uri] + '#annotations:' + item[:id]}</link>
<dc:creator><![CDATA[#{item[:user_info][:display_name] || item[:user]}]]></dc:creator>
</item>
}
end
{
content_type: 'application/rss+xml',
body: HEADER + items.join('') + FOOTER
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment