-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathRakefile
64 lines (57 loc) · 1.93 KB
/
Rakefile
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
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
talks = get("https://pretalx.seagl.org/api/events/#{year}/talks/?limit=1000&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
talks.each do |talk|
write "_archive-sessions/#{year}/#{talk[:title].parameterize}.md", {
title: talk[:title],
pretalx_url: "https://pretalx.seagl.org/#{year}/talk/#{talk[:code]}/",
beginning: talk[:slot][:start],
end: talk[:slot][:end],
presenters: talk[:speakers].map do |speaker|
{
name: speaker[:name],
pretalx_url: "https://pretalx.seagl.org/#{year}/speaker/#{speaker[:code]}/",
biography: speaker[:biography]
}
end,
abstract: talk[:description] ? talk[:abstract] : nil
}.compact, talk[:description] || talk[:abstract]
end
end
def get(url)
puts "Retrieving #{url}"
response = JSON.parse(URI.open(url).read).deep_symbolize_keys!.deep_transform_values! { |v| normalize(v) }
raise "Not implemented for paginated responses" if response[:next]
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