jekyll-indico 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +3 -3
- data/README.md +3 -1
- data/lib/jekyll-indico/core.rb +28 -10
- data/lib/jekyll-indico/generator.rb +11 -8
- data/lib/jekyll-indico/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz: '
|
3
|
+
metadata.gz: 4e2a1ea8813f626061be2c5da553cafe9453aaac
|
4
|
+
data.tar.gz: '06758dd8b0908b58f065a13a5fc8f8990ff1ab0d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f909dd6bffbd0f595c03daa73d2da3fc234a3ff9f72ccca3e35e532a962dada79dc5be4f978b3aa4e4c92edbb6248807d03be92e08658fb7d45c679576a4dc1
|
7
|
+
data.tar.gz: 246baf00d16729890482b79743ef9c625e6976c52bf8c336c91b66bfd039c6a6c3f1333f6984e393e8de366b391ce6be2b499b1ddd257a7b50161b42550967ad
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# Version 0.5
|
2
|
+
|
3
|
+
Added a way to paginate. Use `paginate: N` to iterate over pages of results.
|
4
|
+
|
5
|
+
# Version 0.4.5
|
6
|
+
|
7
|
+
Fix timeout being incorrectly called again.
|
8
|
+
|
9
|
+
# Version 0.4.4
|
10
|
+
|
11
|
+
Fix timeout being incorrectly called.
|
12
|
+
|
13
|
+
# Version 0.4.3
|
14
|
+
|
15
|
+
Fix warning message for classic tokens. Add time printout to help judge need for
|
16
|
+
timeout setting.
|
17
|
+
|
1
18
|
# Version 0.4.2
|
2
19
|
|
3
20
|
Remove broken support for classic tokens. Modern `INDICO_TOKEN` required.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jekyll-indico (0.
|
4
|
+
jekyll-indico (0.5.0)
|
5
5
|
jekyll (>= 3.8, < 5.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -54,12 +54,12 @@ GEM
|
|
54
54
|
public_suffix (4.0.6)
|
55
55
|
rainbow (3.1.1)
|
56
56
|
rake (13.0.6)
|
57
|
-
rb-fsevent (0.11.
|
57
|
+
rb-fsevent (0.11.1)
|
58
58
|
rb-inotify (0.10.1)
|
59
59
|
ffi (~> 1.0)
|
60
60
|
regexp_parser (2.2.0)
|
61
61
|
rexml (3.2.5)
|
62
|
-
rouge (3.
|
62
|
+
rouge (3.28.0)
|
63
63
|
rspec (3.10.0)
|
64
64
|
rspec-core (~> 3.10.0)
|
65
65
|
rspec-expectations (~> 3.10.0)
|
data/README.md
CHANGED
@@ -14,13 +14,15 @@ indico:
|
|
14
14
|
url: https://indico.cern.ch # Indico instance to use (REQUIRED)
|
15
15
|
data: indico # Optional, folder name in _data to use
|
16
16
|
cache-command: bundle exec rake cache # Optional, user msg if you support it
|
17
|
+
paginate: 20 # Optional integer number of results per page (auto-iterates over all pages)
|
18
|
+
timeout: 120 # Optional timeout in number of seconds (default: 60)
|
17
19
|
ids:
|
18
20
|
topical: 10570
|
19
21
|
blueprint: 11329
|
20
22
|
```
|
21
23
|
|
22
24
|
This plugin will automatically use an API token if your environment contains
|
23
|
-
`INDICO_TOKEN`. You should generate this and replace `
|
25
|
+
`INDICO_TOKEN`. You should generate this and replace `INDICO_API_KEY` and
|
24
26
|
`INDICO_SECRET_KEY` with it. You'll want the "Classic API" read permissions set
|
25
27
|
on it.
|
26
28
|
|
data/lib/jekyll-indico/core.rb
CHANGED
@@ -23,10 +23,10 @@ module JekyllIndico
|
|
23
23
|
attr_accessor :dict
|
24
24
|
|
25
25
|
# ID for IRIS-HEP: 10570
|
26
|
-
def initialize(base_url, indico_id, **kargs)
|
26
|
+
def initialize(base_url, indico_id, limit: nil, **kargs)
|
27
27
|
@dict = {}
|
28
28
|
|
29
|
-
download_and_iterate(base_url, indico_id, **kargs) do |i|
|
29
|
+
download_and_iterate(base_url, indico_id, limit: limit, **kargs) do |i|
|
30
30
|
# Trim paragraph tags
|
31
31
|
d = i['description']
|
32
32
|
d = d[3..-1] if d.start_with? '<p>'
|
@@ -62,25 +62,43 @@ module JekyllIndico
|
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
def get_parsed_results(base_url, indico_id, timeout: nil, **params)
|
66
|
+
opts = { use_ssl: true }
|
67
|
+
opts[:read_timeout] = timeout if timeout
|
68
|
+
|
68
69
|
uri = URI.join(base_url, "/export/categ/#{indico_id}.json")
|
69
70
|
uri.query = URI.encode_www_form(params)
|
70
71
|
|
71
72
|
req = Net::HTTP::Get.new(uri)
|
72
73
|
if ENV['INDICO_TOKEN']
|
73
74
|
req['Authorization'] = "Bearer #{ENV['INDICO_TOKEN']}"
|
74
|
-
elsif ENV['INDICO_SECRET_KEY'] || ENV['
|
75
|
+
elsif ENV['INDICO_SECRET_KEY'] || ENV['INDICO_API_KEY']
|
75
76
|
raise Error, 'Use INDICO_TOKEN with a new-style token'
|
76
77
|
end
|
77
78
|
|
78
|
-
response = Net::HTTP.start(uri.hostname, uri.port,
|
79
|
+
response = Net::HTTP.start(uri.hostname, uri.port, **opts) { |http| http.request(req) }
|
79
80
|
|
80
|
-
|
81
|
-
parsed
|
81
|
+
parsed = JSON.parse(response.body)
|
82
|
+
parsed['results']
|
83
|
+
end
|
82
84
|
|
83
|
-
|
85
|
+
# Run a block over each item in the downloaded results
|
86
|
+
def download_and_iterate(base_url, indico_id, limit: nil, **params, &block)
|
87
|
+
params[:limit] = limit if limit
|
88
|
+
params[:pretty] = 'no'
|
89
|
+
|
90
|
+
unless limit
|
91
|
+
results = get_parsed_results(base_url, indico_id, **params)
|
92
|
+
results.each(&block)
|
93
|
+
return
|
94
|
+
end
|
95
|
+
|
96
|
+
0.step.each do |n|
|
97
|
+
results = get_parsed_results(base_url, indico_id, offset: n * limit, **params)
|
98
|
+
break if results.empty?
|
99
|
+
|
100
|
+
results.each(&block)
|
101
|
+
end
|
84
102
|
end
|
85
103
|
end
|
86
104
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'benchmark'
|
4
|
+
require 'net/http'
|
3
5
|
require 'yaml'
|
4
6
|
|
5
7
|
require 'jekyll'
|
6
8
|
|
7
9
|
require 'jekyll-indico/core'
|
8
10
|
|
9
|
-
require 'net/http'
|
10
|
-
|
11
11
|
module JekyllIndico
|
12
12
|
# This is a Jekyll Generator
|
13
13
|
class GetIndico < Jekyll::Generator
|
@@ -16,9 +16,6 @@ module JekyllIndico
|
|
16
16
|
@site = site
|
17
17
|
@cache_msg = @site.config.dig('indico', 'cache-command')
|
18
18
|
|
19
|
-
timeout = @site.config.dig('indico', 'timeout')
|
20
|
-
Net::HTTP.read_timeout = timeout if timeout
|
21
|
-
|
22
19
|
meeting_ids = @site.config.dig('indico', 'ids')
|
23
20
|
raise MissingIDs, 'indico: ids: MISSING from your config!' unless meeting_ids
|
24
21
|
raise MissingIDs, 'indico: ids: must be a hash!' unless meeting_ids.is_a?(Hash)
|
@@ -37,13 +34,19 @@ module JekyllIndico
|
|
37
34
|
data_path = @site.config.dig('indico', 'data') || 'indico'
|
38
35
|
@site.data[data_path] = {} unless @site.data.key? data_path
|
39
36
|
|
37
|
+
timeout = @site.config.dig('indico', 'timeout')
|
38
|
+
limit = @site.config.dig('indico', 'paginate')
|
39
|
+
|
40
40
|
# Do nothing if already downloaded
|
41
41
|
return if @site.data[data_path].key? name
|
42
42
|
|
43
43
|
msg = @cache_msg ? " - run `#{@cache_msg}` to cache" : ''
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
print "Accessing Indico meeting API for #{name}:#{number}#{msg}"
|
45
|
+
time = Benchmark.realtime do
|
46
|
+
iris_meeting = Meetings.new(base_url, number, timeout: timeout, limit: limit)
|
47
|
+
@site.data[data_path][name] = iris_meeting.dict
|
48
|
+
end
|
49
|
+
puts ", took #{time.round(1)} s"
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-indico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Schreiner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|