diff --git a/README.md b/README.md index 9baf774..1a06e17 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,26 @@ This repository contains `html2rss` feed configurations for many websites. +## Dynamic Parameters + +Configs must include a `parameters` section to define default values for dynamic parameters: + +```yaml +parameters: + query: + type: string + default: "technology" + category: + type: string + default: "news" + +channel: + url: https://example.com/search?q=%s&cat=%s + # ... rest of config +``` + +The `type` field specifies the parameter type (currently only `string` is supported), and `default` provides the default value when no parameter is explicitly provided. + ## Documentation - [Main Documentation](https://html2rss.github.io/html2rss-configs/) diff --git a/lib/html2rss/configs/bbc.co.uk/available_episodes.yml b/lib/html2rss/configs/bbc.co.uk/available_episodes.yml index ac07b6f..2113a9c 100644 --- a/lib/html2rss/configs/bbc.co.uk/available_episodes.yml +++ b/lib/html2rss/configs/bbc.co.uk/available_episodes.yml @@ -1,3 +1,8 @@ +parameters: + id: + type: string + default: "b006wkfp" + channel: url: https://www.bbc.co.uk/programmes/%s/episodes/player time_zone: UTC diff --git a/lib/html2rss/configs/blog.mondediplo.net/feed.yml b/lib/html2rss/configs/blog.mondediplo.net/feed.yml index b3b9a81..8675339 100644 --- a/lib/html2rss/configs/blog.mondediplo.net/feed.yml +++ b/lib/html2rss/configs/blog.mondediplo.net/feed.yml @@ -1,3 +1,8 @@ +parameters: + blog: + type: string + default: "-Defense-en-ligne-" + channel: url: https://blog.mondediplo.net/%s time_zone: Europe/Paris diff --git a/lib/html2rss/configs/github.com/releases.yml b/lib/html2rss/configs/github.com/releases.yml index 9019703..c313825 100644 --- a/lib/html2rss/configs/github.com/releases.yml +++ b/lib/html2rss/configs/github.com/releases.yml @@ -1,3 +1,11 @@ +parameters: + username: + type: string + default: "nuxt" + repository: + type: string + default: "nuxt.js" + channel: url: https://github.com/%s/%s/releases time_zone: UTC diff --git a/lib/html2rss/configs/imdb.com/ratings.yml b/lib/html2rss/configs/imdb.com/ratings.yml index 3fffc50..46cae73 100644 --- a/lib/html2rss/configs/imdb.com/ratings.yml +++ b/lib/html2rss/configs/imdb.com/ratings.yml @@ -1,3 +1,8 @@ +parameters: + user_id: + type: string + default: "ur7019649" + channel: url: https://www.imdb.com/user/%s/ratings time_zone: UTC diff --git a/lib/html2rss/configs/spiegel.de/impressum_autor.yml b/lib/html2rss/configs/spiegel.de/impressum_autor.yml index 1320bd7..637f83e 100644 --- a/lib/html2rss/configs/spiegel.de/impressum_autor.yml +++ b/lib/html2rss/configs/spiegel.de/impressum_autor.yml @@ -1,3 +1,8 @@ +parameters: + id: + type: string + default: "975b6ae0-0001-0003-0000-000000018282" + channel: url: "https://www.spiegel.de/impressum/autor-%s" time_zone: Europe/Berlin @@ -13,7 +18,7 @@ selectors: url: selector: "section > a" extractor: "href" - descripton: + description: selector: ".leading-loose" published_at: selector: "footer" diff --git a/spec/html2rss/configs/apnews.com/hub.yml_spec.rb b/spec/html2rss/configs/apnews.com/hub.yml_spec.rb index 1170446..7550870 100644 --- a/spec/html2rss/configs/apnews.com/hub.yml_spec.rb +++ b/spec/html2rss/configs/apnews.com/hub.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'apnews.com/hub.yml' do - it_behaves_like 'config.yml', 'apnews.com/hub.yml', section: 'world-news' + it_behaves_like 'config.yml', 'apnews.com/hub.yml' end diff --git a/spec/html2rss/configs/bbc.co.uk/available_episodes.yml_spec.rb b/spec/html2rss/configs/bbc.co.uk/available_episodes.yml_spec.rb index 79d63f3..00e89c0 100644 --- a/spec/html2rss/configs/bbc.co.uk/available_episodes.yml_spec.rb +++ b/spec/html2rss/configs/bbc.co.uk/available_episodes.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'bbc.co.uk/available-episodes.yml' do - it_behaves_like 'config.yml', 'bbc.co.uk/available_episodes.yml', id: 'b006wkfp' + it_behaves_like 'config.yml', 'bbc.co.uk/available_episodes.yml' end diff --git a/spec/html2rss/configs/blog.mondediplo.net/feed.yml_spec.rb b/spec/html2rss/configs/blog.mondediplo.net/feed.yml_spec.rb index ff79cfb..ca1b274 100644 --- a/spec/html2rss/configs/blog.mondediplo.net/feed.yml_spec.rb +++ b/spec/html2rss/configs/blog.mondediplo.net/feed.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'blog.mondediplo.net/feed.yml' do - it_behaves_like 'config.yml', 'blog.mondediplo.net/feed.yml', blog: '-Defense-en-ligne-' + it_behaves_like 'config.yml', 'blog.mondediplo.net/feed.yml' end diff --git a/spec/html2rss/configs/cnet.com/section_sub.yml_spec.rb b/spec/html2rss/configs/cnet.com/section_sub.yml_spec.rb index 7940c97..9bf7d68 100644 --- a/spec/html2rss/configs/cnet.com/section_sub.yml_spec.rb +++ b/spec/html2rss/configs/cnet.com/section_sub.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'cnet.com/section_sub.yml' do - it_behaves_like 'config.yml', 'cnet.com/section_sub.yml', section: 'culture', sub: 'internet' + it_behaves_like 'config.yml', 'cnet.com/section_sub.yml' end diff --git a/spec/html2rss/configs/github.com/releases.yml_spec.rb b/spec/html2rss/configs/github.com/releases.yml_spec.rb index 319ee6a..72042dc 100644 --- a/spec/html2rss/configs/github.com/releases.yml_spec.rb +++ b/spec/html2rss/configs/github.com/releases.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'github.com/releases.yml' do - it_behaves_like 'config.yml', 'github.com/releases.yml', username: 'nuxt', repository: 'nuxt.js' + it_behaves_like 'config.yml', 'github.com/releases.yml' end diff --git a/spec/html2rss/configs/imdb.com/ratings.yml_spec.rb b/spec/html2rss/configs/imdb.com/ratings.yml_spec.rb index b233986..964d7fa 100644 --- a/spec/html2rss/configs/imdb.com/ratings.yml_spec.rb +++ b/spec/html2rss/configs/imdb.com/ratings.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'imdb.com/ratings.yml' do - it_behaves_like 'config.yml', 'imdb.com/ratings.yml', user_id: 'ur7019649' + it_behaves_like 'config.yml', 'imdb.com/ratings.yml' end diff --git a/spec/html2rss/configs/spiegel.de/impressum_autor.yml_spec.rb b/spec/html2rss/configs/spiegel.de/impressum_autor.yml_spec.rb index db7272b..9c44d93 100644 --- a/spec/html2rss/configs/spiegel.de/impressum_autor.yml_spec.rb +++ b/spec/html2rss/configs/spiegel.de/impressum_autor.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'spiegel.de/impressum_autor.yml' do - it_behaves_like 'config.yml', 'spiegel.de/impressum_autor.yml', id: '975b6ae0-0001-0003-0000-000000018282' + it_behaves_like 'config.yml', 'spiegel.de/impressum_autor.yml' end diff --git a/spec/html2rss/configs/webentwickler-jobs.de/in.yml_spec.rb b/spec/html2rss/configs/webentwickler-jobs.de/in.yml_spec.rb index c7bd2d3..99a02bc 100644 --- a/spec/html2rss/configs/webentwickler-jobs.de/in.yml_spec.rb +++ b/spec/html2rss/configs/webentwickler-jobs.de/in.yml_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.describe 'webentwickler-jobs.de/in.yml' do - it_behaves_like 'config.yml', 'webentwickler-jobs.de/in.yml', region: 'berlin' + it_behaves_like 'config.yml', 'webentwickler-jobs.de/in.yml' end diff --git a/spec/support/shared_examples/config.yml_spec.rb b/spec/support/shared_examples/config.yml_spec.rb index 1f556a7..fa57427 100644 --- a/spec/support/shared_examples/config.yml_spec.rb +++ b/spec/support/shared_examples/config.yml_spec.rb @@ -26,7 +26,18 @@ config = {}.merge Html2rss::Configs.find_by_name(feed_name) config.merge!(global_config.dup) - config[:params] = params if params + + # Use provided params or extract defaults from parameters section + if params + config[:params] = params + elsif config[:parameters] + default_params = {} + config[:parameters].each do |param_name, param_config| + default_params[param_name] = param_config[:default] if param_config[:default] + end + config[:params] = default_params unless default_params.empty? + end + config end @@ -61,6 +72,16 @@ end end + context 'with parameters present' do + it 'has valid parameter definitions', :aggregate_failures do + yaml['parameters']&.each do |param_name, param_config| + expect(param_config).to be_a(Hash), "parameter `#{param_name}` should be a hash" + expect(param_config['type']).to eq('string'), "parameter `#{param_name}` should have type 'string'" + expect(param_config['default']).not_to be_nil, "parameter `#{param_name}` should have a default value" + end + end + end + context 'with selectors present' do it 'has required selectors', :aggregate_failures do %w[items title].each do |required_attribute|