-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathRakefile
More file actions
68 lines (60 loc) · 2.22 KB
/
Copy pathRakefile
File metadata and controls
68 lines (60 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
desc 'Import data from pretalx into Jekyll data'
task :import, [:year] do |_t, args|
require 'active_support/core_ext/hash/deep_transform_values'
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/string/inflections'
require 'json'
require 'open-uri'
require 'pathname'
require 'yaml'
year = args.year
# Retrieve data
submissions = get("https://pretalx.seagl.org/api/events/#{year}/submissions/?expand=slots,speakers&pending_state=confirmed")
# Create a file for the conference
write "_archive-conferences/#{year}.md", {
pretalx_url: "https://pretalx.seagl.org/#{year}/"
}
# Create a file for each session
submissions.each do |submission|
raise 'Not implemented for multiple slots' unless submission[:slots].count == 1
write "_archive-sessions/#{year}/#{submission[:title].parameterize}.md", {
title: submission[:title],
pretalx_url: "https://pretalx.seagl.org/#{year}/talk/#{submission[:code]}/",
beginning: submission[:slots][0][:start],
end: submission[:slots][0][:end],
presenters: submission[:speakers].map do |speaker|
{
name: speaker[:name],
pretalx_url: "https://pretalx.seagl.org/#{year}/speaker/#{speaker[:code]}/",
biography: speaker[:biography]
}
end,
abstract: submission[:description] ? submission[:abstract] : nil
}.compact, submission[:description] || submission[:abstract]
end
end
def get(url)
Enumerator.produce({ next: url, results: [] }) { |response|
puts "Retrieving #{response[:next]}"
JSON.parse(URI.open(response[:next]).read).deep_symbolize_keys!.deep_transform_values! { |v| normalize(v) }
}
.take_while { |response| response[:next] and sleep 1 }
.flat_map { |response| response[:results] }
end
def normalize(value)
case value
when String then value
.gsub(/(?<=[.!?,;:] ) +(?=\w)/, "")
.gsub(/(?:(?<=[^ ]) )?(?:^ +)?\r?\n/, "\n")
.strip
.presence
else value
end
end
def write(path, frontmatter, body = nil)
puts "Creating #{path}"
pathname = Pathname.new(path)
pathname.dirname.mkpath
pathname.write("#{frontmatter.deep_stringify_keys.to_yaml}---\n#{body && "\n#{body}\n"}")
end