diff --git a/CHANGELOG.md b/CHANGELOG.md index 56245b7..62ed225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ +# Version 0.2.0 + +Support for base URLs. The `indico: url:` parameter is *required*. + # Version 0.1.0 First version to be published, pulled from the IRIS-HEP website. Extra features added during the transition include: + * Config settings for IDs and data path. * `jekyll-indico-cache` script has customizable `--config` location. * Some basic unit testing diff --git a/Gemfile.lock b/Gemfile.lock index a4a5b14..6522583 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - jekyll-indico (0.1.0) + jekyll-indico (0.2.0) jekyll (>= 3.8, < 5.0) GEM diff --git a/README.md b/README.md index 8c2b9f8..92cfaea 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Your `_config.yaml` file should contain the categories you want to download: ```yaml indico: + url: https://indico.cern.ch # Indico instance to use (REQUIRED) data: indico # Optional, folder name in _data to use ids: topical: 10570 diff --git a/exe/jekyll-indico-cache b/exe/jekyll-indico-cache index c7efd48..d796200 100755 --- a/exe/jekyll-indico-cache +++ b/exe/jekyll-indico-cache @@ -19,8 +19,9 @@ puts "Reading #{options[:config]}" config = YAML.safe_load(File.read(options[:config])) meeting_ids = JekyllIndico::Meetings.meeting_ids(config) +base_url = JekyllIndico::Meetings.base_url(config) data_path = config.dig('indico', 'data') || 'indico' -JekyllIndico.cache(meeting_ids, data_path) do |name, number| +JekyllIndico.cache(base_url, meeting_ids, data_path) do |name, number| puts "Accessing #{number} for #{name}" end diff --git a/lib/jekyll-indico/cache.rb b/lib/jekyll-indico/cache.rb index c0ab714..fa2c67a 100644 --- a/lib/jekyll-indico/cache.rb +++ b/lib/jekyll-indico/cache.rb @@ -9,7 +9,7 @@ module JekyllIndico # This will cache the hash of meeting IDs given into the data_path in _data # in the current directory. - def self.cache(meeting_ids, data_path) + def self.cache(base_url, meeting_ids, data_path) meeting_ids.each do |name, number| yield name, number indico_dir = Pathname.new('_data') / data_path @@ -17,7 +17,7 @@ def self.cache(meeting_ids, data_path) indico_dir.mkdir unless indico_dir.directory? folder.mkdir unless folder.directory? - iris_meeting = JekyllIndico::Meetings.new number + iris_meeting = JekyllIndico::Meetings.new(base_url, number) iris_meeting.to_files(folder) { |key| puts "Making #{folder / key}.yml\n" } end end diff --git a/lib/jekyll-indico/core.rb b/lib/jekyll-indico/core.rb index 5a2db14..823bf3d 100644 --- a/lib/jekyll-indico/core.rb +++ b/lib/jekyll-indico/core.rb @@ -9,15 +9,21 @@ require 'openssl' module JekyllIndico + class Error < StandardError + end + + class MissingURL < Error + end + # Look for topical meetings class Meetings attr_accessor :dict # ID for IRIS-HEP: 10570 - def initialize(indico_id, **kargs) + def initialize(base_url, indico_id, **kargs) @dict = {} - download_and_iterate(indico_id, **kargs) do |i| + download_and_iterate(base_url, indico_id, **kargs) do |i| # Trim paragraph tags d = i['description'] d = d[3..-1] if d.start_with? '
' @@ -56,11 +62,19 @@ def self.meeting_ids(config = {}) config.dig('indico', 'ids') end + # Get base URL from a config + def self.base_url(config = {}) + url = config.dig('indico', 'url') + raise MissingURL('indico: url: MISSING from your config!') unless url + + url + end + private # Run a block over each item in the downloaded results - def download_and_iterate(indico_id, **kargs, &block) - url = build_url(indico_id, **kargs) + def download_and_iterate(base_url, indico_id, **kargs, &block) + url = build_url(base_url, indico_id, **kargs) uri = URI.parse(url) response = Net::HTTP.get_response(uri) @@ -77,7 +91,7 @@ def join_url(indico_id, options) end # Automatically signs request if environment has INDICO_API/SECRET_KEY - def build_url(indico_id, **kargs) + def build_url(base_url, indico_id, **kargs) kargs[:pretty] = 'no' if ENV['INDICO_API_KEY'] @@ -89,7 +103,7 @@ def build_url(indico_id, **kargs) end end - "https://indico.cern.ch#{join_url(indico_id, kargs)}" + "#{base_url}#{join_url(indico_id, kargs)}" end end end diff --git a/lib/jekyll-indico/generator.rb b/lib/jekyll-indico/generator.rb index d6479f7..4d4ec91 100644 --- a/lib/jekyll-indico/generator.rb +++ b/lib/jekyll-indico/generator.rb @@ -15,13 +15,15 @@ def generate(site) meeting_ids = Meetings.meeting_ids(@site.config) meeting_ids.each do |name, number| - collect_meeting name.to_s, number + collect_meeting(name.to_s, number) end end private def collect_meeting(name, number) + base_url = Meetings.base_url(@site.config) + data_path = @site.config.dig('indico', 'data') || 'indico' @site.data[data_path] = {} unless @site.data.key? data_path @@ -30,7 +32,7 @@ def collect_meeting(name, number) puts "Accessing Indico meeting API for #{name}:#{number} " \ '- run `bundle exec rake cache` to cache' - iris_meeting = Meetings.new(number) + iris_meeting = Meetings.new(base_url, number) @site.data[data_path][name] = iris_meeting.dict end end diff --git a/lib/jekyll-indico/version.rb b/lib/jekyll-indico/version.rb index 2241896..b76a7a0 100644 --- a/lib/jekyll-indico/version.rb +++ b/lib/jekyll-indico/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module JekyllIndico - VERSION = '0.1.1' + VERSION = '0.2.0' end diff --git a/spec/jekyll-indico_spec.rb b/spec/jekyll-indico_spec.rb index c5425e1..2729497 100644 --- a/spec/jekyll-indico_spec.rb +++ b/spec/jekyll-indico_spec.rb @@ -7,9 +7,9 @@ expect(JekyllIndico::VERSION).not_to be nil end - context 'with a topical meeting' do + context 'with a CERN topical meeting' do before :all do - @meeting = JekyllIndico::Meetings.new 10570 + @meeting = JekyllIndico::Meetings.new('https://indico.cern.ch', 10570) end it 'has expected meetings' do