-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig.rb
80 lines (64 loc) · 2.28 KB
/
config.rb
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
# frozen_string_literal: true
require 'sciolyff/interpreter'
ignore '/results/placeholder.html'
ignore '/results/template.html'
if (num = ENV['MIN_BUILD'])
ignore '/results/index.html'
ignore '/results/schools.html'
ignore '/results/schools.csv'
ignore '/results/events.csv'
num = num.empty? ? 1 : num.to_i
@app.data.recents[0...num].each do |recent|
filename = recent.delete_suffix('.yaml').to_sym
proxy "/results/#{filename}.html",
'/results/template.html',
locals: { i: SciolyFF::Interpreter.new(@app.data.to_h[filename]) }
end
return
end
# Proxy pages
# https://middlemanapp.com/advanced/dynamic-pages/
interpreters = {}
@app.data.to_h.each do |filename, tournament|
next unless filename.to_s.start_with?(/[0-9]/)
interpreters[filename.to_s] = SciolyFF::Interpreter.new(tournament)
end
interpreters = interpreters.sort_by do |_, i|
[Date.new(2019, 10, 17) - i.tournament.date,
i.tournament.state,
i.tournament.location,
i.tournament.division]
end.to_h
page '/results/index.html', locals: { interpreters: interpreters }
page '/results/schools.html', locals: { interpreters: interpreters }
page '/results/schools.csv', locals: { interpreters: interpreters }
page '/results/events.csv', locals: { interpreters: interpreters }
# strip trailing whitespace from CSV files
after_build do |builder|
base = File.join(config[:build_dir], 'results')
builder.thor.gsub_file File.join(base, 'schools.csv'), /\s+\Z/, ''
builder.thor.gsub_file File.join(base, 'events.csv' ), /\s+\Z/, ''
end
return if ENV['INDEX_ONLY']
interpreters.each do |filename, interpreter|
proxy "/results/#{filename}.html",
'/results/template.html',
locals: { i: interpreter }
end
data.upcoming.each do |info|
next unless info.key?(:file) && !interpreters.key?(info[:file])
proxy "/results/#{info[:file]}.html",
'/results/placeholder.html',
locals: { t: info }
end
# Activate and configure extensions
# https://middlemanapp.com/advanced/configuration/#configuring-extensions
activate :external_pipeline,
name: :webpack,
command: if build?
'yarn run webpack --bail'
else
'yarn run webpack --watch -d'
end,
source: '.tmp/dist',
latency: 1