nanoc-feeds 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f40b9f32b3ed641d3930ef1a5a6dc1020a8cda66c66176cea5497a47058a369c
4
- data.tar.gz: 13bdb8b0b8497e288639650857a2f8f0df7a17e3053497ee153ff88a1c1c2424
3
+ metadata.gz: 2ca33b8b6cb61359bd1d6ef05e638504c92cf66a26ce8fbf7ba3c60ebff7413d
4
+ data.tar.gz: 369d309c128f02e0a34197752d8e6d08108723e8379fcd5d4bcb2701d55d500c
5
5
  SHA512:
6
- metadata.gz: cb5f63cb408efe141e29af0b478ad02b387457e476372b9bf7ff51af3fb7b4aac2cd88f2ae732d82102dda2df0499d1b610a8381b05955389642e08f3789276e
7
- data.tar.gz: 98b33920ee6695e209f2bcd4aa4df775a662d5bc2944aa55bbf3eee5b6fe0873505334a4e9d3ad7c3fc492d046711bf2da334856751b99daaa91ed44a558d14a
6
+ metadata.gz: 16148e2eda57af3da5165ee443357a73bd0fd7c7e9949178924d37369078bf4e425ecce8dc0825f116d1315a4f11310880023041c9c084eb8af7f389ea36097d
7
+ data.tar.gz: 4ba60e0d65d3be045514ad720f8adcd6e712b2c9000dfcefeebbaa95dffeafe9acbf23dbae6b1f3fb7ea0867b18fe99a9c16425447607c6974549995af941d4e
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Nanoc::Feeds::Builders::JsonFeedBuilder
4
+ def initialize(
5
+ config:,
6
+ articles:,
7
+ limit: 5,
8
+ title: config[:title]
9
+ )
10
+ @config = config
11
+ @articles = articles
12
+ @limit = limit
13
+ @title = title
14
+ end
15
+
16
+ def build
17
+ items = @articles.first(@limit).map { |article| build_article(article) }
18
+
19
+ {
20
+ version: "https://jsonfeed.org/version/1.1",
21
+ title: @title,
22
+ home_page_url: "#{@config[:base_url]}",
23
+ feed_url: feed_url,
24
+ items: items
25
+ }.to_json
26
+ end
27
+
28
+ def build_article(article)
29
+ {
30
+ id: "#{@config[:base_url]}#{article.identifier.without_exts}",
31
+ url: url_for(article),
32
+ title: article[:title] || @title,
33
+ content_text: "#{article.compiled_content}",
34
+ date_published: "#{article[:created_at].rfc3339}"
35
+ }
36
+ end
37
+ end
@@ -1,9 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
  require "nanoc"
3
5
 
4
6
  module Nanoc::Feeds::Helpers::Feeds
5
7
  include Nanoc::Helpers::Blogging
6
8
 
9
+ # @option params [Number] :limit
10
+ # @option params [Array] :articles
11
+ # @option params [Proc] :id_proc
12
+ # @option params [String] :title
7
13
  def feed(params = {})
8
14
  if @rep.name == :json
9
15
  json_feed(params)
@@ -12,29 +18,34 @@ module Nanoc::Feeds::Helpers::Feeds
12
18
  end
13
19
  end
14
20
 
21
+ # @option params [Number] :limit
22
+ # @option params [Array] :articles
23
+ # @option params [Proc] :id_proc
24
+ # @option params [String] :title
15
25
  def json_feed(params = {})
16
- articles = params[:articles]
26
+ articles = params[:articles] || articles # articles is a helper method from Nanoc::Helpers::Blogging
17
27
  articles = articles.first(params[:limit]) if params[:limit]
18
28
  title = params[:title] || @config[:title]
29
+ id_proc = params[:id_proc] || Proc.new { |article| atom_tag_for(article) }
19
30
 
20
- items = articles.map { |article| build_for_article(article, title) }
21
-
31
+ feed_items = articles.map { |article| build_for_article(article, title, id_proc:) }
22
32
  {
23
33
  version: "https://jsonfeed.org/version/1.1",
24
34
  title: title,
25
- home_page_url: "#{config[:base_url]}",
35
+ home_page_url: "#{@config[:base_url]}",
26
36
  feed_url: feed_url,
27
- items: items
37
+ items: feed_items
28
38
  }.to_json
29
39
  end
30
40
 
31
- def build_for_article(article, title)
41
+ private
42
+ def build_for_article(article, title, id_proc:)
32
43
  {
33
- id: "#{config[:base_url]}#{article.identifier.without_exts}",
44
+ id: id_proc.call(article),
34
45
  url: url_for(article),
35
46
  title: article[:title] || title,
36
47
  content_text: "#{article.compiled_content}",
37
- date_published: "#{article[:created_at].rfc3339}"
48
+ date_published: "#{attribute_to_time(article[:created_at]).to_datetime.rfc3339}"
38
49
  }
39
50
  end
40
51
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Feeds
5
- VERSION = "0.1.2"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-feeds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Emhofer
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: zeitwerk
@@ -93,6 +93,20 @@ dependencies:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: mocha
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
96
110
  email:
97
111
  - michael@emhofer.net
98
112
  executables: []
@@ -103,6 +117,7 @@ files:
103
117
  - README.md
104
118
  - Rakefile
105
119
  - lib/nanoc/feeds.rb
120
+ - lib/nanoc/feeds/builders/json_feed_builder.rb
106
121
  - lib/nanoc/feeds/helpers/feeds.rb
107
122
  - lib/nanoc/feeds/version.rb
108
123
  - sig/nanoc/feeds.rbs
@@ -126,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
141
  - !ruby/object:Gem::Version
127
142
  version: '0'
128
143
  requirements: []
129
- rubygems_version: 3.6.2
144
+ rubygems_version: 4.0.10
130
145
  specification_version: 4
131
146
  summary: A set of helpers for generating additional feeds in nanoc. Currenntly JSON
132
147
  and Atom feeds are supported.