forked from alexwlchan/alexwlchan.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom_feeds.rb
35 lines (30 loc) · 962 Bytes
/
atom_feeds.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'nokogiri'
module Jekyll
module AtomFeedFilters
# Remove inline attributes from an HTML string that aren't allowed in
# an Atom feed, according to https://github.com/rubys/feedvalidator
#
# Params:
# +html+:: HTML string to clean.
#
def strip_html_attrs(html)
doc = Nokogiri::HTML.fragment(html)
doc.xpath('style|@style|.//@style|@data-lang|.//@data-lang|@controls|.//@controls|@aria-hidden|.//@aria-hidden').remove
doc.to_s
end
# Minify an XML string.
#
# Here minification just means removing all whitespace that comes
# after a '>'. This isn't as nice as using a proper XML parser, but
# I've been unable to get that working in Ruby.
# TODO: Use Nokogiri to do this properly.
#
# Params:
# +xml+:: XML string to minify.
#
def minify_xml(xml)
xml.gsub(%r|>\s+|, ">")
end
end
end
Liquid::Template::register_filter(Jekyll::AtomFeedFilters)