Skip to content

Commit 1135981

Browse files
committed
feat(deps): use html2rss in latest development status
Signed-off-by: Gil Desmarais <[email protected]>
1 parent 51f0d14 commit 1135981

File tree

10 files changed

+167
-67
lines changed

10 files changed

+167
-67
lines changed

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ source 'https://rubygems.org'
44

55
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

7-
gem 'html2rss', '~> 0.14'
7+
# gem 'html2rss', '~> 0.14'
8+
gem 'html2rss', github: 'html2rss/html2rss'
9+
810
gem 'html2rss-configs', github: 'html2rss/html2rss-configs'
911

1012
# Use these instead of the two above (uncomment them) when developing locally:

Gemfile.lock

Lines changed: 85 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
GIT
2+
remote: https://github.com/html2rss/html2rss
3+
revision: 19957e05b8859c7c7680a9319a90c560661cf439
4+
specs:
5+
html2rss (0.17.0)
6+
addressable (~> 2.7)
7+
dry-validation
8+
faraday (> 2.0.1, < 3.0)
9+
faraday-follow_redirects
10+
kramdown
11+
mime-types (> 3.0)
12+
nokogiri (>= 1.10, < 2.0)
13+
parallel
14+
puppeteer-ruby
15+
regexp_parser
16+
reverse_markdown (~> 3.0)
17+
rss
18+
sanitize
19+
thor
20+
tzinfo
21+
zeitwerk
22+
123
GIT
224
remote: https://github.com/html2rss/html2rss-configs
325
revision: 6aadc0cf35c10642a4f15022e3ee9902360d3171
@@ -22,6 +44,41 @@ GEM
2244
crass (1.0.6)
2345
diff-lcs (1.6.0)
2446
docile (1.4.1)
47+
dry-configurable (1.3.0)
48+
dry-core (~> 1.1)
49+
zeitwerk (~> 2.6)
50+
dry-core (1.1.0)
51+
concurrent-ruby (~> 1.0)
52+
logger
53+
zeitwerk (~> 2.6)
54+
dry-inflector (1.2.0)
55+
dry-initializer (3.2.0)
56+
dry-logic (1.6.0)
57+
bigdecimal
58+
concurrent-ruby (~> 1.0)
59+
dry-core (~> 1.1)
60+
zeitwerk (~> 2.6)
61+
dry-schema (1.14.1)
62+
concurrent-ruby (~> 1.0)
63+
dry-configurable (~> 1.0, >= 1.0.1)
64+
dry-core (~> 1.1)
65+
dry-initializer (~> 3.2)
66+
dry-logic (~> 1.5)
67+
dry-types (~> 1.8)
68+
zeitwerk (~> 2.6)
69+
dry-types (1.8.2)
70+
bigdecimal (~> 3.0)
71+
concurrent-ruby (~> 1.0)
72+
dry-core (~> 1.0)
73+
dry-inflector (~> 1.0)
74+
dry-logic (~> 1.4)
75+
zeitwerk (~> 2.6)
76+
dry-validation (1.11.1)
77+
concurrent-ruby (~> 1.0)
78+
dry-core (~> 1.1)
79+
dry-initializer (~> 3.2)
80+
dry-schema (~> 1.14)
81+
zeitwerk (~> 2.6)
2582
erubi (1.13.1)
2683
faraday (2.12.2)
2784
faraday-net_http (>= 2.0, < 3.5)
@@ -32,22 +89,6 @@ GEM
3289
faraday-net_http (3.4.0)
3390
net-http (>= 0.5.0)
3491
hashdiff (1.1.2)
35-
html2rss (0.17.0)
36-
addressable (~> 2.7)
37-
faraday (> 2.0.1, < 3.0)
38-
faraday-follow_redirects
39-
kramdown
40-
mime-types (> 3.0)
41-
nokogiri (>= 1.10, < 2.0)
42-
parallel
43-
puppeteer-ruby
44-
regexp_parser
45-
reverse_markdown (~> 3.0)
46-
rss
47-
sanitize (~> 6.0)
48-
thor
49-
tzinfo
50-
zeitwerk
5192
json (2.10.2)
5293
kramdown (2.5.1)
5394
rexml (>= 3.3.9)
@@ -58,23 +99,25 @@ GEM
5899
logger
59100
mime-types-data (~> 3.2015)
60101
mime-types-data (3.2025.0304)
61-
mini_portile2 (2.8.8)
62102
net-http (0.6.0)
63103
uri
64104
nio4r (2.7.4)
65-
nokogiri (1.18.4)
66-
mini_portile2 (~> 2.8.2)
67-
racc (~> 1.4)
68105
nokogiri (1.18.4-aarch64-linux-gnu)
69106
racc (~> 1.4)
107+
nokogiri (1.18.4-aarch64-linux-musl)
108+
racc (~> 1.4)
70109
nokogiri (1.18.4-arm-linux-gnu)
71110
racc (~> 1.4)
111+
nokogiri (1.18.4-arm-linux-musl)
112+
racc (~> 1.4)
72113
nokogiri (1.18.4-arm64-darwin)
73114
racc (~> 1.4)
74115
nokogiri (1.18.4-x86_64-darwin)
75116
racc (~> 1.4)
76117
nokogiri (1.18.4-x86_64-linux-gnu)
77118
racc (~> 1.4)
119+
nokogiri (1.18.4-x86_64-linux-musl)
120+
racc (~> 1.4)
78121
parallel (1.26.3)
79122
parser (3.3.7.1)
80123
ast (~> 2.4.1)
@@ -144,9 +187,9 @@ GEM
144187
lint_roller (~> 1.1)
145188
rubocop (~> 1.72, >= 1.72.1)
146189
ruby-progressbar (1.13.0)
147-
sanitize (6.1.3)
190+
sanitize (7.0.0)
148191
crass (~> 1.0.2)
149-
nokogiri (>= 1.12.0)
192+
nokogiri (>= 1.16.8)
150193
sentry-ruby (5.23.0)
151194
bigdecimal
152195
concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -180,19 +223,21 @@ GEM
180223
zeitwerk (2.7.2)
181224

182225
PLATFORMS
183-
aarch64-linux
184-
arm-linux
226+
aarch64-linux-gnu
227+
aarch64-linux-musl
228+
arm-linux-gnu
229+
arm-linux-musl
185230
arm64-darwin
186-
x86-linux
187231
x86_64-darwin
188-
x86_64-linux
232+
x86_64-linux-gnu
233+
x86_64-linux-musl
189234

190235
DEPENDENCIES
191236
base64
192237
byebug
193238
climate_control
194239
erubi
195-
html2rss (~> 0.14)
240+
html2rss!
196241
html2rss-configs!
197242
parallel
198243
puma
@@ -229,12 +274,20 @@ CHECKSUMS
229274
crass (1.0.6) sha256=dc516022a56e7b3b156099abc81b6d2b08ea1ed12676ac7a5657617f012bd45d
230275
diff-lcs (1.6.0) sha256=a1e7f7b272962f8fc769358ad00001b87cdcf32ba349d6c70c6b544613d2da2e
231276
docile (1.4.1) sha256=96159be799bfa73cdb721b840e9802126e4e03dfc26863db73647204c727f21e
277+
dry-configurable (1.3.0) sha256=882d862858567fc1210d2549d4c090f34370fc1bb7c5c1933de3fe792e18afa8
278+
dry-core (1.1.0) sha256=0903821a9707649a7da545a2cd88e20f3a663ab1c5288abd7f914fa7751ab195
279+
dry-inflector (1.2.0) sha256=22f5d0b50fd57074ae57e2ca17e3b300e57564c218269dcf82ff3e42d3f38f2e
280+
dry-initializer (3.2.0) sha256=37d59798f912dc0a1efe14a4db4a9306989007b302dcd5f25d0a2a20c166c4e3
281+
dry-logic (1.6.0) sha256=da6fedbc0f90fc41f9b0cc7e6f05f5d529d1efaef6c8dcc8e0733f685745cea2
282+
dry-schema (1.14.1) sha256=2fcd7539a7099cacae6a22f6a3a2c1846fe5afeb1c841cde432c89c6cb9b9ff1
283+
dry-types (1.8.2) sha256=c84e9ada69419c727c3b12e191e0ed7d2c6d58d040d55e79ea16e0ebf8b3ec0f
284+
dry-validation (1.11.1) sha256=70900bb5a2d911c8aab566d3e360c6bff389b8bf92ea8e04885ce51c41ff8085
232285
erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9
233286
faraday (2.12.2) sha256=157339c25c7b8bcb739f5cf1207cb0cefe8fa1c65027266bcbc34c90c84b9ad6
234287
faraday-follow_redirects (0.3.0) sha256=d92d975635e2c7fe525dd494fcd4b9bb7f0a4a0ec0d5f4c15c729530fdb807f9
235288
faraday-net_http (3.4.0) sha256=a1f1e4cd6a2cf21599c8221595e27582d9936819977bbd4089a601f24c64e54a
236289
hashdiff (1.1.2) sha256=2c30eeded6ed3dce8401d2b5b99e6963fe5f14ed85e60dd9e33c545a44b71a77
237-
html2rss (0.17.0) sha256=f97c978272212fb9b67dfe8f9712a212ff22c9a812f574e9d64df703a8278370
290+
html2rss (0.17.0)
238291
html2rss-configs (0.2.0)
239292
json (2.10.2) sha256=34e0eada93022b2a0a3345bb0b5efddb6e9ff5be7c48e409cfb54ff8a36a8b06
240293
kramdown (2.5.1) sha256=87bbb6abd9d3cebe4fc1f33e367c392b4500e6f8fa19dd61c0972cf4afe7368c
@@ -243,15 +296,16 @@ CHECKSUMS
243296
logger (1.6.6) sha256=dd618d24e637715472732e7eed02e33cfbdf56deaad225edd0f1f89d38024017
244297
mime-types (3.6.0) sha256=6f71db957840ceae44211531eff3e2f7e0dd4645fefb5f535dbaeb6307ab6464
245298
mime-types-data (3.2025.0304) sha256=7ed9385881432d708b7f4e9cf2a4a9e1d4e8bf8abcd08283c23a0d5cd7205097
246-
mini_portile2 (2.8.8) sha256=8e47136cdac04ce81750bb6c09733b37895bf06962554e4b4056d78168d70a75
247299
net-http (0.6.0) sha256=9621b20c137898af9d890556848c93603716cab516dc2c89b01a38b894e259fb
248300
nio4r (2.7.4) sha256=d95dee68e0bb251b8ff90ac3423a511e3b784124e5db7ff5f4813a220ae73ca9
249-
nokogiri (1.18.4) sha256=bb7820521c1bbae1d3e0092ff03b27a8e700912b37d80f962b7e4567947a64ac
250301
nokogiri (1.18.4-aarch64-linux-gnu) sha256=8f2263cef9953ce09bd5293d76c9bbd3013d2f94d1cca67783dfe6635c529deb
302+
nokogiri (1.18.4-aarch64-linux-musl) sha256=4e231f8ba3128cfc2ef0cc0bdc807d7ce71fc62cb6a78216e817be8631fe6a96
251303
nokogiri (1.18.4-arm-linux-gnu) sha256=cc2945e2c19560a61a97737e6bd3b329edb1f82ca204d46a18e5e98ad0a550a6
304+
nokogiri (1.18.4-arm-linux-musl) sha256=4fb7f44de0cd85abfa869e4cfb619410da174ebf9fbe26ae0caa65462b818bcb
252305
nokogiri (1.18.4-arm64-darwin) sha256=73902663b23b1123282b9c0b6d9654b1fb286dfee8d65cb1f6029087b7f0d037
253306
nokogiri (1.18.4-x86_64-darwin) sha256=e4776f58eea9b94d05caf8bf351e3c6aa1cce01edcc2ed530f3c302c13178965
254307
nokogiri (1.18.4-x86_64-linux-gnu) sha256=b1c6407b346b88704e97a342a80acd4755175324e624da34d0c5cfdc8d34191e
308+
nokogiri (1.18.4-x86_64-linux-musl) sha256=ea7c0356a70f3d2d0d76315b533877013d20368d5c9f437c38e0bd462c4844dc
255309
parallel (1.26.3) sha256=d86babb7a2b814be9f4b81587bf0b6ce2da7d45969fab24d8ae4bf2bb4d4c7ef
256310
parser (3.3.7.1) sha256=7dbe61618025519024ac72402a6677ead02099587a5538e84371b76659e6aca1
257311
public_suffix (6.0.1) sha256=61d44e1cab5cbbbe5b31068481cf16976dd0dc1b6b07bd95617ef8c5e3e00c6f
@@ -282,7 +336,7 @@ CHECKSUMS
282336
rubocop-rspec (3.5.0) sha256=710c942fe1af884ba8eea75cbb8bdbb051929a2208880a6fc2e2dce1eed5304c
283337
rubocop-thread_safety (0.7.2) sha256=bd51449c420b1ddda5672b71a39706367402beb55aaf19fc020c1868717f31f6
284338
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
285-
sanitize (6.1.3) sha256=a42ce5f933d82765a8243599d5ab2e8867237e76cf5a699caaddfe60bb944152
339+
sanitize (7.0.0) sha256=269d1b9d7326e69307723af5643ec032ff86ad616e72a3b36d301ac75a273984
286340
sentry-ruby (5.23.0) sha256=8e8bb2f9a56a267a50fcba947f2ae131b6542f45fc3bb5764c2c25ba68f385cc
287341
simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5
288342
simplecov-html (0.13.1) sha256=5dab0b7ee612e60e9887ad57693832fdf4695b4c0c859eaea5f95c18791ef10b

app.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,38 @@ def self.development? = ENV['RACK_ENV'] == 'development'
8484
end
8585

8686
r.on String, String do |folder_name, config_name_with_ext|
87-
handle_html2rss_configs(request, folder_name, config_name_with_ext)
87+
response['Content-Type'] = CONTENT_TYPE_RSS
88+
89+
name = "#{folder_name}/#{File.basename(config_name_with_ext, '.*')}"
90+
config = Html2rss::Configs.find_by_name(name).dup
91+
92+
if (params = request.params).any?
93+
config[:params] ||= {}
94+
config[:params].merge!(params)
95+
end
96+
97+
feed = Html2rss.feed(config)
98+
99+
HttpCache.expires(response, feed.channel.ttl.to_i * 60, cache_control: 'public')
100+
101+
feed.to_xml
88102
end
89103

90104
r.on String do |config_name_with_ext|
91-
handle_local_config_feeds(request, config_name_with_ext)
105+
response['Content-Type'] = CONTENT_TYPE_RSS
106+
107+
config = LocalConfig.find(File.basename(config_name_with_ext, '.*'))
108+
109+
if (params = request.params).any?
110+
config[:params] ||= {}
111+
config[:params].merge!(params)
112+
end
113+
114+
feed = Html2rss.feed(config)
115+
116+
HttpCache.expires(response, feed.channel.ttl.to_i * 60, cache_control: 'public')
117+
118+
feed.to_xml
92119
end
93120
end
94121

app/html2rss_facade.rb

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,47 @@ class Html2rssFacade
1414

1515
attr_reader :feed_config, :typecast_params
1616

17-
##
18-
# @param name [String] the name of a html2rss-configs provided config.
19-
# @param typecast_params [Object]
20-
# @return [String] the serialized RSS feed
21-
def self.from_config(name, typecast_params, &)
22-
feed_config = Html2rss::Configs.find_by_name(name)
23-
new(feed_config, typecast_params).feed(&)
24-
end
17+
class << self
18+
##
19+
# @param name [String] the name of a html2rss-configs provided config.
20+
# @param typecast_params [Object]
21+
# @return [String] the serialized RSS feed
22+
def from_config(name, typecast_params, &)
23+
feed_config = Html2rss::Configs.find_by_name(name)
24+
new(feed_config, typecast_params).feed(&)
25+
end
2526

26-
##
27-
# @param name [String] the name of a feed in the file `config/feeds.yml`
28-
# @param typecast_params [Object]
29-
# @return [String] the serialized RSS feed
30-
def self.from_local_config(name, typecast_params, &)
31-
feed_config = LocalConfig.find(name)
32-
new(feed_config, typecast_params).feed(&)
33-
end
27+
##
28+
# @param name [String] the name of a feed in the file `config/feeds.yml`
29+
# @param typecast_params [Object]
30+
# @return [String] the serialized RSS feed
31+
def from_local_config(name, typecast_params, &)
32+
feed_config = LocalConfig.find(name)
33+
new(feed_config, typecast_params).feed(&)
34+
end
3435

35-
##
36-
# @param feed_config [Hash<Symbol, Object>]
37-
# @param typecast_params [Object]
38-
# @param global_config [Hash<Symbol, Object>]
39-
# @return [Html2rss::Config]
40-
# @raise [Roda::RodaPlugins::TypecastParams::Error]
41-
def self.feed_config_to_config(feed_config, typecast_params, global_config: LocalConfig.global)
42-
dynamic_params = Html2rss::Config::Channel.required_params_for_config(feed_config[:channel])
43-
.to_h { |name| [name, typecast_params.str!(name)] }
44-
Html2rss::Config.new(feed_config, global_config, dynamic_params)
36+
##
37+
# @param feed_config [Hash<Symbol, Object>]
38+
# @param typecast_params [Object]
39+
# @param global_config [Hash<Symbol, Object>]
40+
# @return [Html2rss::Config]
41+
# @raise [Roda::RodaPlugins::TypecastParams::Error]
42+
def feed_config_to_config(feed_config, typecast_params, global_config: LocalConfig.global)
43+
params = required_params_for_config(feed_config[:channel])
44+
.to_h { |name| [name, typecast_params.str!(name)] }
45+
46+
config = global_config.merge(feed_config)
47+
config[:params] = params if params.any?
48+
config
49+
end
50+
51+
private
52+
53+
def required_params_for_config(config)
54+
config.each_with_object(Set.new) do |(_, value), required_params|
55+
required_params.merge(value.scan(/%<(\w+)>[s|d]/).flatten) if value.is_a?(String)
56+
end
57+
end
4558
end
4659

4760
##

app/http_cache.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module HttpCache
1515
# @param seconds [Integer]
1616
# @param cache_control [String, nil]
1717
def expires(response, seconds, cache_control: nil)
18+
expires_now(response) and return if seconds <= 0
19+
1820
response['Expires'] = (Time.now + seconds).httpdate
1921

2022
cache_value = "max-age=#{seconds}"

app/ssrf_filter_strategy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def execute
1616
response = SsrfFilter.get(ctx.url, headers:)
1717

1818
Html2rss::RequestService::Response.new(body: response.body,
19+
url: ctx.url,
1920
headers: response.to_hash.transform_values(&:first))
2021
end
2122
end

helpers/handle_error.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ module Web
88
class App
99
def handle_error(error) # rubocop:disable Metrics/MethodLength
1010
case error
11-
when Html2rss::Config::ParamsMissing,
11+
when Html2rss::Config::DynamicParams::ParamsMissing,
1212
Roda::RodaPlugins::TypecastParams::Error
1313
set_error_response('Parameters missing or invalid', 422)
14-
when Html2rss::AttributePostProcessors::UnknownPostProcessorName,
15-
Html2rss::ItemExtractors::UnknownExtractorName,
16-
Html2rss::Config::ChannelMissing
14+
when Html2rss::Selectors::PostProcessors::UnknownPostProcessorName,
15+
Html2rss::Selectors::Extractors::UnknownExtractorName
1716
set_error_response('Invalid feed config', 422)
1817
when LocalConfig::NotFound,
1918
Html2rss::Configs::ConfigNotFound

helpers/handle_html2rss_configs.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def handle_html2rss_configs(request, _folder_name, _config_name_with_ext)
88

99
Html2rssFacade.from_config(path.full_config_name, typecast_params) do |config|
1010
response['Content-Type'] = CONTENT_TYPE_RSS
11-
HttpCache.expires(response, config.ttl * 60, cache_control: 'public')
11+
12+
HttpCache.expires(response, config.dig(:channel, :ttl).to_i * 60, cache_control: 'public')
1213
end
1314
end
1415
end

helpers/handle_local_config_feeds.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def handle_local_config_feeds(request, _config_name_with_ext)
88

99
Html2rssFacade.from_local_config(path.full_config_name, typecast_params) do |config|
1010
response['Content-Type'] = CONTENT_TYPE_RSS
11-
HttpCache.expires(response, config.ttl * 60, cache_control: 'public')
11+
12+
HttpCache.expires(response, config.dig(:channel, :ttl).to_i * 60, cache_control: 'public')
1213
end
1314
end
1415
end

routes/auto_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class App
2727

2828
response['Content-Type'] = CONTENT_TYPE_RSS
2929

30-
url = Addressable::URI.parse Base64.urlsafe_decode64(encoded_url)
30+
url = Addressable::URI.parse(Base64.urlsafe_decode64(encoded_url)).to_s
3131
rss = Html2rss.auto_source(url, strategy:)
3232

3333
# Unfortunately, Ruby's rss gem does not provide a direct method to

0 commit comments

Comments
 (0)