Skip to content

Commit

Permalink
feat!: settable url
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Feb 4, 2021
1 parent 6a6a2b1 commit f3ec4fa
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
jekyll-indico (0.1.0)
jekyll-indico (0.2.0)
jekyll (>= 3.8, < 5.0)

GEM
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion exe/jekyll-indico-cache
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/jekyll-indico/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
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
folder = indico_dir / name.to_s
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
Expand Down
26 changes: 20 additions & 6 deletions lib/jekyll-indico/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? '<p>'
Expand Down Expand Up @@ -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)

Expand All @@ -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']
Expand All @@ -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
6 changes: 4 additions & 2 deletions lib/jekyll-indico/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-indico/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module JekyllIndico
VERSION = '0.1.1'
VERSION = '0.2.0'
end
4 changes: 2 additions & 2 deletions spec/jekyll-indico_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3ec4fa

Please sign in to comment.