Class: Abqari::Feed
- Inherits:
-
Object
- Object
- Abqari::Feed
- Defined in:
- lib/abqari/feed.rb
Overview
Generates RSS + JSON Feed for a single collection. Per-collection
feeds are opt-in via collections.<name>.feeds.enabled (default
true for posts — back-compat — and false for everything else).
Output paths:
posts → /feed.xml + /feed.json (back-compat root paths)
<other> → /<collection>/feed.xml + /<collection>/feed.json
The root /feed.xml for posts is intentional: pre-existing
subscribers + feed-reader caches keep working without redirects.
Constant Summary collapse
- MAX_ITEMS =
20
Class Method Summary collapse
-
.write_all(site) ⇒ Object
Class-level entry point: writes feeds for every collection that has
feeds.enabled: true.
Instance Method Summary collapse
-
#initialize(site, collection_name = 'posts') ⇒ Feed
constructor
A new instance of Feed.
- #write ⇒ Object
Constructor Details
#initialize(site, collection_name = 'posts') ⇒ Feed
Returns a new instance of Feed.
21 22 23 24 |
# File 'lib/abqari/feed.rb', line 21 def initialize(site, collection_name = 'posts') @site = site @collection_name = collection_name end |
Class Method Details
.write_all(site) ⇒ Object
Class-level entry point: writes feeds for every collection that
has feeds.enabled: true. Defaults to true only for posts so
existing sites don't suddenly start emitting photo / publication
feeds without opt-in.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/abqari/feed.rb', line 39 def self.write_all(site) site.collections.each do |name, cfg| next unless cfg.fetch('enabled', true) feeds_enabled = cfg.dig('feeds', 'enabled') feeds_enabled = (name == 'posts') if feeds_enabled.nil? next unless feeds_enabled new(site, name).write end end |
Instance Method Details
#write ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/abqari/feed.rb', line 26 def write return if items.empty? return unless base_url FileUtils.mkdir_p(File.dirname(rss_path)) File.write(rss_path, rss) File.write(json_path, json_feed) end |