Class: Lifer::Builder::JSONFeed
- Inherits:
-
Lifer::Builder
- Object
- Lifer::Builder
- Lifer::Builder::JSONFeed
- Defined in:
- lib/lifer/builder/json_feed.rb
Overview
This builds JSON feed compliant with the JSON Feed 1.1 specification. Note that we don’t currently support all of the features of JSON Feed, but it shouldn’t be too hard to add them.
The JSON Feed builder can be configured in a number of ways:
-
Boolean
Simply set ‘json_feed: true` or `json_feed: false` to enable or disable a feed for a collection. If `true`, a JSON feed will be build to `/name-of-collection.json` at the root of the Lifer output directory.
-
Simple
Simply set ‘json_feed: name-of-output-file.json` to specify the name of the output JSON Feed file.
-
Fine-grained
Provide an object under ‘json_feed:` for more fine-grained control over configuration. The following sub-settings are supported:
-
‘authors:` A list of authors to fall back to if an entry does not have its own authors data. Each author can include the following fields:
- `name:` The author's name. - `url:` A URL that represents the author. - `avatar:` The URL to an avatar that represents the author. -
‘content_format:` The format of the feed entries for the entire feed. Either `html` or `text`. (Default: `html`.)
-
‘count:` - The limit of JSON Feed items that should be included in the output document. Leave unset or set to `0` to include all entries.
-
‘expired:` Set the expired flag on the feed to broadcast whether the feed will continue to be updated.
-
‘home_page_url:` A URL that represents the home page of the current feed.
-
‘url:` The path to the filename of the output JSON Feed file.
-
Constant Summary collapse
- JSON_FEED_VERSION =
As of this writing, we support the latest version of the JSON Feed specification.
"1.1"
Class Method Summary collapse
-
.execute(root:) ⇒ void
Traverses and renders a JSON Feed for each JSON Feed-enabled, feedable collection in the configured output directory for the Lifer project.
Instance Method Summary collapse
-
#execute ⇒ void
Traverses and renders a JSON Feed for JSON Feed-enabled feedable collections.
Methods inherited from Lifer::Builder
Class Method Details
.execute(root:) ⇒ void
This method returns an undefined value.
Traverses and renders a JSON Feed for each JSON Feed-enabled, feedable collection in the configured output directory for the Lifer project.
67 68 69 70 71 |
# File 'lib/lifer/builder/json_feed.rb', line 67 def execute(root:) Dir.chdir Lifer.output_directory do new(root:).execute end end |
Instance Method Details
#execute ⇒ void
This method returns an undefined value.
Traverses and renders a JSON Feed for JSON Feed-enabled feedable collections.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/lifer/builder/json_feed.rb', line 78 def execute collections_with_feeds.each do |collection| next unless (filename = output_filename(collection)) FileUtils.mkdir_p File.dirname(filename) File.open filename, "w" do |file| file.puts( json_feed_for(collection) do |current_feed| max_index = max_feed_items(collection) - 1 collection.entries .select { |entry| entry.feedable? }[0..max_index] .each { |entry| json_feed_entry(current_feed, entry, collection) } end ) end end end |