Skip to content

Commit 321eec4

Browse files
committed
toplevel: generate RSS feeds
1 parent 4c1257a commit 321eec4

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

lib/clayoven/toplevel.rb

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "fileutils"
44
require "progressbar"
55
require "sitemap_generator"
6+
require "rss"
67

78
# :nodoc:
89
module Clayoven
@@ -249,13 +250,12 @@ def self.unhidden_content_files(content_files)
249250
end
250251
end
251252

252-
# Return IndexPage and ContentPage entries to render; we work with index_files and
253-
# content_files, because converting them to Page objects prematurely will result in unnecessary
254-
# `log --follow` invocations.
255-
def self.pages_to_render(index_files, content_files, is_aggressive)
256-
dirty_index_pages, dirty_content_pages =
257-
dirty_pages index_files, content_files, is_aggressive
258-
253+
# Return IndexPage and ContentPage entries to render
254+
def self.pages_to_render(
255+
dirty_index_pages,
256+
dirty_content_pages,
257+
content_files
258+
)
259259
# Reject hidden content_files
260260
dirty_index_pages.each do |dip|
261261
content_pages =
@@ -345,6 +345,27 @@ def self.generate_sitemap(all_pages)
345345
end
346346
end
347347

348+
# Generate `feed.xml` from content_pages.
349+
def self.generate_rss(content_pages, lastmod)
350+
puts "[#{"XML".green} ]: Generating RSS feed"
351+
rss =
352+
RSS::Maker.make("atom") do |maker|
353+
maker.channel.author = "Ramkumar Ramachandra"
354+
maker.channel.updated = lastmod
355+
maker.channel.about = "https://artagnon.com/feed.xml"
356+
maker.channel.title = "RSS Feed for artagnon.com"
357+
358+
content_pages.each do |p|
359+
maker.items.new_item do |item|
360+
item.link = p.permalink
361+
item.title = p.title
362+
item.updated = p.lastmod
363+
end
364+
end
365+
end
366+
File.open("feed.xml", _ = "w") { |targetio| targetio.write rss }
367+
end
368+
348369
# Generate HTML, minify the design, and generate the sitemap.
349370
def self.generate_site(genpages, topics, is_aggressive)
350371
generate_html genpages, topics if genpages.any?
@@ -377,11 +398,20 @@ def self.main(is_aggressive: false)
377398
# If the template changes, we're definitely in aggressive mode
378399
is_aggressive ||= @git.requires_aggressive?
379400

380-
# Get a list of pages to render, genpages
381-
genpages = pages_to_render index_files, content_files, is_aggressive
401+
# Get a list of pages to render
402+
dirty_index_pages, dirty_content_pages =
403+
dirty_pages index_files, content_files, is_aggressive
404+
genpages =
405+
pages_to_render dirty_index_pages, dirty_content_pages, content_files
382406

383407
# Generate the genpages
384408
generate_site genpages, topics, is_aggressive
409+
410+
# Generate the RSS feed from content pages
411+
if is_aggressive
412+
generate_rss dirty_content_pages,
413+
Clayoven::Toplevel.sitewide_lastmod(genpages)
414+
end
385415
end
386416
end
387417
end

0 commit comments

Comments
 (0)