2011-09-04 20:28:53 +02:00
|
|
|
# build rss feed
|
|
|
|
def rss_feed
|
|
|
|
require "rss/maker"
|
|
|
|
version = "2.0"
|
|
|
|
|
|
|
|
content = RSS::Maker.make(version) do |rss|
|
2012-04-18 02:08:04 +02:00
|
|
|
rss.channel.title = @site.title
|
|
|
|
rss.channel.link = @site.url
|
2011-09-04 20:28:53 +02:00
|
|
|
rss.channel.author = "mail@muflax.com"
|
2012-04-18 02:08:04 +02:00
|
|
|
rss.channel.description = @site.title
|
2011-09-04 20:28:53 +02:00
|
|
|
rss.items.do_sort = true # sort items by date
|
|
|
|
|
2013-01-26 09:47:18 +01:00
|
|
|
# use non-draft articles
|
2013-01-26 09:10:33 +01:00
|
|
|
@site.items_by_date.last(5).each do |item|
|
|
|
|
i = rss.items.new_item
|
|
|
|
i.title = "#{item[:title]}"
|
|
|
|
i.link = "#{@site.url}" + item.path
|
|
|
|
i.date = item[:date].to_time
|
|
|
|
i.description = tidy(item.compiled_content).force_encoding("utf-8")
|
2012-02-05 05:40:57 +01:00
|
|
|
end
|
|
|
|
|
2013-01-26 09:47:18 +01:00
|
|
|
# mod date is newest article
|
2012-04-18 02:08:04 +02:00
|
|
|
last_article = @site.items_by_date.last[:date].to_time
|
2013-01-26 09:47:18 +01:00
|
|
|
rss.channel.date = last_article
|
2011-09-04 20:28:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
content
|
|
|
|
end
|
|
|
|
|
2012-06-25 12:49:29 +02:00
|
|
|
def rss_feed_merged
|
|
|
|
require "rss"
|
|
|
|
version = "2.0"
|
|
|
|
|
|
|
|
date = Time.new 0
|
|
|
|
items = []
|
|
|
|
|
|
|
|
# read individual feeds and include them
|
|
|
|
@site.site_yaml["sites"].keys.each do |name|
|
2013-01-26 09:10:33 +01:00
|
|
|
next if name == "muflax"
|
|
|
|
|
2012-06-25 12:49:29 +02:00
|
|
|
feed = RSS::Parser.parse(File.open("out/#{name}/rss.xml"))
|
|
|
|
date = [feed.channel.date, date].max
|
2012-11-16 11:19:24 +01:00
|
|
|
feed.items.each do |item|
|
|
|
|
# fix absolute links to other sites
|
|
|
|
item.description.gsub! /(?<tag> (src|href) = ["'] ) (?<url> \/ \w+)/x, "\\k<tag>#{site_url(name)}\\k<url>"
|
|
|
|
end
|
2012-06-25 12:49:29 +02:00
|
|
|
items.concat feed.items
|
|
|
|
end
|
|
|
|
|
|
|
|
# build merged feed
|
|
|
|
merged_feed = RSS::Maker.make(version) do |rss|
|
|
|
|
rss.channel.title = "muflax"
|
|
|
|
rss.channel.link = "http://muflax.com"
|
|
|
|
rss.channel.author = "mail@muflax.com"
|
|
|
|
rss.channel.description = "read ALL the muflax!"
|
|
|
|
end
|
|
|
|
merged_feed.items.concat items.sort_by(&:date).reverse.take(10)
|
|
|
|
|
|
|
|
# write it
|
|
|
|
merged_feed
|
|
|
|
end
|