Skip to content

Instantly share code, notes, and snippets.

@anthonymoralez
Last active April 27, 2017 19:18
Show Gist options
  • Save anthonymoralez/24a7fe359987ac296a550edfd5edc4a1 to your computer and use it in GitHub Desktop.
Save anthonymoralez/24a7fe359987ac296a550edfd5edc4a1 to your computer and use it in GitHub Desktop.
Adding RSS and RSS Friendly Gists
---
title: Don't look too good, nor talk too wise
author_name: Anthony Moralez
author_uri: http://www.anthonymoralez.com
is_hidden: true
---
<%= atom_feed %>
def get_raw_gist(user, gist_id, file)
url = URI.parse("https://gist.githubusercontent.com/#{user}/#{gist_id}/raw/#{file}")
res = Net::HTTP.get_response(url)
res.body.force_encoding("UTF-8")
end
script_tag_regex = /(?<script_tag><script\s+src=["']https:\/\/gist\.github\.com\/(?<user>[^\/]+)\/(?<gist_id>[^\.]+)\.js\?file=(?<file>[^"']+)["']\s*>.*<\/script>)/
Nanoc::Filter.define(:gists) do |content, params|
content.gsub(script_tag_regex) { |match|
raw_gist = get_raw_gist($2, $3, $4)
$1 + "\n<noscript><code>" + h(raw_gist) + "</code></noscript>\n"
}
end
<p>Some stuff that introduces a gist:</p>
<script src="https://gist.github.com/anthonymoralez/6f8621ab14061dc9487016939bdcfe99.js?file=nanoc.sh"></script>
<noscript><code>$ nanoc</code></noscript>
---
title: "Heroku Buildpack for Nanoc"
created_at: 2017-04-26 10:04:16 -0700
kind: article
published: true
excerpt: Short blurb for the beginning of this article.
---
Some stuff that introduces a gist:
<script src="https://gist.github.com/anthonymoralez/6f8621ab14061dc9487016939bdcfe99.js?file=nanoc.sh"></script>
compile '/feed/*.erb' do
filter :erb
write item.identifier.without_ext
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment