forked from OSUOSC/project-official-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
270 lines (252 loc) · 8.05 KB
/
Copy pathRakefile
File metadata and controls
270 lines (252 loc) · 8.05 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
require "bundler/gem_tasks"
require "jekyll"
require "listen"
require "yaml"
require 'fileutils'
require 'date'
NEWS_PATHNAME = '_posts/*'
def listen_ignore_paths(base, options)
[
/_config\.ya?ml/,
/_site/,
/\.jekyll-metadata/
]
end
def local_render_yaml(news_pathname)
basename = Pathname.new('.').expand_path
Dir[basename.join(news_pathname).to_s].each do |post|
html = ''
html << <<-EOF
<section class="page__content" itemprop="text">
<hr />
<h2>This week in technology, open source, and Linux!</h2>
<h2>Disclaimer</h2>
<ul>
<li> The views expressed in this presentation are those of the presentator(s).</li>
<li> They are not endorsed by or affiliated with any of the people, companies, or entities mentioned.</li>
<li> No guarantees are made that the information in this presentation are free of errors.</li>
</ul>
<h2>Contributing to the weekly rundown</h2>
<ul>
<li>Have something you'd like to talk about or see on the weekly meetings?</li>
<li>Feel free to add it to the weekly rundown!</li>
<li>Repository is available on <a href="https://github.com/OSUOSC/osc-weekly-rundown">Github</a></li>
</ul>
<hr />
<h2>Stories</h2>
<ul>
EOF
File.open(post, 'a') do |file|
file.puts html
end
page = YAML.load_file(post)
page['stories'].each_with_index do |story,index|
html = ''
html << <<-EOF
<li><a href="{{ page.multipage.first_path | absolute_url }}#{if index!=1 then "#{index + 2}" + '/' end}">#{story["title"]}</a></li>
EOF
File.open(post, 'a') do |file|
file.puts html
end
end
page['stories'].each do |story|
html = ''
html << <<-EOF
{% page_break %}
<hr />
# [#{story["title"]}](#{story["link"]})

#{story["notes"]}
EOF
File.open(post, 'a') do |file|
file.puts html
end
end
html = ''
html << <<-HTML
{% page_break %}
<hr />
<h1>Fin</h1>
<ul>
<li>Anything we missed?</li>
<li>Feel free to share!</li>
</ul>
HTML
File.open(post, 'a') do |file|
file.puts html
end
end
end
#
# This is the way to get the content of the file after the YAML front matter
#
def local_clear_yaml(pathname)
basename = Pathname.new('.').expand_path
Dir[basename.join(pathname).to_s].each do |post|
yaml = File.read(post)[/\A---(.|\n)*?---/]
File.open(post, 'w') do |file|
file.puts yaml
end
end
end
def new_post_template()
base = Pathname.new('.').expand_path
skel = ''
skel << <<-EOF
---
layout: multipage
multipage: true
collection: news
stories:
- title: ""
link: ""
image: ""
notes: |
---
EOF
date = Date.parse('Thursday')
delta = date > Date.today ? 0 : 7
ndate = date + delta
file_date = ndate.strftime('%Y-%m-%d')
if File.exist? File.expand_path "#{base}/_posts/#{file_date}-meeting.md"
puts "File for the next meeting already exists at: #{base}/_posts/#{file_date}-meeting.md"
else
File.open("#{base}/_posts/#{file_date}-meeting.md", 'wb') do |file|
file.puts skel
end
end
end
def enter_event(file, date, event)
# Get the yaml info fo the post
page = YAML.load_file(event)
# default for "meeting" is "success"
btn_type = "success"
case page['type']
when "Convention"
btn_type = "warning"
when "Volunteer"
btn_type = "danger"
when "Internal"
btn_type = "info"
when "Party"
btn_type = "light-outline"
end
tmp_file = File.open("/tmp/calendar.tmp", 'w')
#tmp = ''
File.readlines(file).each do |line|
idx = line.index(date.strftime(' %d')).to_i
if idx > 0
idx = idx + date.strftime(' %d').length
tmp_file << line.insert(idx, "<br /> [#{page['title']}](/events/#{event.rpartition('/')[2][0..-4]}/){: .btn .btn--#{btn_type}}")
else
#tmp << line
tmp_file << line
end
end
tmp_file.close
FileUtils.mv(tmp_file, file)
#puts tmp
end
def calendar_skeleton(basename, date)
File.open("#{basename}/_calendar/#{date.strftime('%Y-%m')}-01-calendar.md", 'wb') do |file|
# What day of the week is the first in numbers? Sunday is zero
first_day_num = Date.new(date.year, date.month, 01).strftime('%w').to_i
# What is the last day fo the month
# The append here is actually an "add 'n' to month" command
last_day_date = Date.new(date.year, (date >> 1).month, 01)
# A raw '-' subtracts one day from the date
last_day_num = (last_day_date - 1).strftime('%d').to_i
# Since we're using the full jekyll file format (YYYY-MM-DD-title.md) to get the date,
# we are going to make the url pretty.
table = "---\npermalink: /calendar/#{date.strftime('%Y-%m')}/\n---\n"
table << <<-EOF
|Sun|Mon|Tue|Wed|Thu|Fri|Sat|
|:---:||:---:|:---:|:---:|:---:|:---:|:---:|
EOF
# First row - have to factor in first_day_num
str = "| "
table << "#{str.ljust((first_day_num * 2 + 2), str)}"
current_day = 1
(1..(7 - first_day_num )).each do |i|
table << "#{i.to_s.rjust(2, "0")} | "
current_day += 1
end
table << "\n"
# Cycle through the full weeks
while (eow = (current_day + 7)) < last_day_num do
while current_day < eow do
table << "| #{current_day.to_s.rjust(2, "0")}"
current_day += 1
end
table << " |\n"
end
# Finish it off
end_padding = (7 - (last_day_num - current_day))
((current_day)..(last_day_num)).each do |i|
table << "| #{current_day.to_s.rjust(2, "0")}"
current_day += 1
end
str = "| "
# Fix off-by-one error
(1..(end_padding)).each do |_|
#table << "#{str.ljust((end_padding - 1), str)}"
table << " |"
end
file.puts table
end
end
#
# TODO: Support events with multiple date ranges
#
def populate_calendar(basename)
calendar_directory = '_calendar/'
events_directory = '_events/'
# TODO: Make sure this is ruby-esque
FileUtils.rm_rf(basename.join(calendar_directory).to_s)
FileUtils::mkdir_p(basename.join(calendar_directory).to_s)
# Create current month's file right off the bat, b/c we link to that and it _always_ needs to exist, even if it's during the summer, and there are no events that month
calendar_skeleton(basename, Date.today)
Dir[basename.join(events_directory).to_s + "*"].each do |event|
date = Date.strptime(event.rpartition('/')[2][0..9], '%Y-%m-%d')
month_file = "#{basename}/_calendar/#{date.strftime('%Y-%m')}-01-calendar.md"
if File.exist? File.path(month_file)
enter_event(month_file, date, event)
else
# File not yet created - create the calendar skeleton and populate file
calendar_skeleton(basename, date)
enter_event(month_file, date, event)
end
end
end
task :clean do
basename = Pathname.new('.').expand_path
local_clear_yaml(NEWS_PATHNAME)
FileUtils.rm_rf(basename.join('_site/').to_s)
FileUtils.rm_rf(basename.join('_calendar/').to_s)
end
task :gen_site do
# Clean shit up first
basename = Pathname.new('.').expand_path
local_clear_yaml(NEWS_PATHNAME)
FileUtils.rm_rf(basename.join('_site/').to_s)
FileUtils.rm_rf(basename.join('_calendar/').to_s)
# Render site
local_render_yaml(NEWS_PATHNAME)
populate_calendar(basename)
options = {
"destination" => basename.join('_site').to_s,
"theme" => "minimal-mistakes-jekyll",
"future" => true
}
options = Jekyll.configuration(options)
site = Jekyll::Site.new(options)
Jekyll::Command.process_site(site)
# Clean up our mess, but leave `_site/`
local_clear_yaml(NEWS_PATHNAME)
end
task :new_post do
FileUtils.rm_rf(basename.join('_site/').to_s)
FileUtils.rm_rf(basename.join('_calendar/').to_s)
local_clear_yaml(NEWS_PATHNAME)
new_post_template()
end