-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathworkshops.rb
More file actions
executable file
·81 lines (69 loc) · 2.4 KB
/
workshops.rb
File metadata and controls
executable file
·81 lines (69 loc) · 2.4 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
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby
require "csv"
require "active_support/all"
require "yaml"
def parameterize(string, separator: "-")
# Turn unwanted chars into the separator.
parameterized_string = string.downcase.gsub(/[^a-z0-9\-_]+/, separator)
unless separator.nil? || separator.empty?
re_leading_trailing_separator = /^-|-$/
parameterized_string.gsub!(re_leading_trailing_separator, "".freeze)
end
parameterized_string
end
def stub_speaker(name)
return unless name
id = parameterize(name)
return if @speakers.select { |x| x["id"] == id }.first
last = name.gsub(/.* /, "")
@speakers << { id: id, name: name, last: last }.stringify_keys
end
# open speakers so we can add to it
speakers_yml = "_data/speakers.yml"
@speakers = File.file?(speakers_yml) ? YAML.load_file(speakers_yml) : []
# parse _data/conf.yml to get workshop date string
conf = YAML.load_file("_data/conf.yml")
workshop_day = conf["days"].find {|d| d["workshops"]}["date-data"].gsub(/T.*/, "")
CSV.foreach(ARGV[0], headers: true).each do |row|
outcomes = row["outcomes"]
requirements = row["requirements"]
max = row["max"]
time = row["time"].downcase
speaker1 = row["speaker1"]&.strip
speaker2 = row["speaker2"]&.strip || ""
speaker3 = speaker2.empty? ? speaker1 : "#{speaker1}, #{speaker2}"
title = row["title"]
description = row["description"]
fn = "_posts/#{workshop_day}-#{parameterize(title)}.md"
puts fn
File.open(fn, "w") do |f|
f.puts "---"
f.puts "layout: presentation"
f.puts "type: workshop"
f.puts "categories: workshops"
f.puts "full: false"
f.puts "learning-outcomes: \"#{outcomes}\""
f.puts "attendee-requirements: \"#{requirements}\""
f.puts "max-attendees: #{max}"
f.puts "time: #{time}"
f.puts "startTime: 9:00am" if time == "am" || time == "full"
f.puts "startTime: 1:30pm" if time == "pm"
f.puts "endTime: 12:00pm" if time == "am"
f.puts "endTime: 4:30pm" if time =="pm" || time == "full"
f.puts "location: "
f.puts "room: "
f.puts "speakers:"
f.puts "- #{parameterize(speaker1)}"
(speaker2.split(",") || []).each do |s|
f.puts "- #{parameterize(s)}"
end
f.puts "speaker-text: #{speaker3}"
f.puts "title: \"#{title}\""
f.puts "---"
f.puts description
end
# stub speakers
[speaker1, speaker2].each { |s| stub_speaker(s) }
end
# write updated speakers
File.open(speakers_yml, "w") { |file| file.write(@speakers.to_yaml) }