2016-12-11 00:55:11 +01:00
|
|
|
module PreprocessHelper
|
|
|
|
def ignore_old_blogposts
|
|
|
|
@items.delete_if do |item|
|
2017-09-30 17:42:52 +02:00
|
|
|
path = item.identifier.to_s
|
|
|
|
next unless path.start_with?('/blog/')
|
|
|
|
year = path.gsub(%r{/blog/(\d\d)-\d\d/.*}, '\1').to_i
|
|
|
|
year < 16
|
2016-12-11 00:55:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_blog_attributes
|
|
|
|
@items.find_all('/blog/**/*').each do |i|
|
2017-05-03 23:08:15 +02:00
|
|
|
raise "#{i.identifier} doesn't have 'created_at'" unless i[:created_at]
|
2017-02-09 02:37:43 +01:00
|
|
|
i.update_attributes(
|
2016-12-11 00:55:11 +01:00
|
|
|
# Tag all posts with article (for Blogging helper)
|
|
|
|
kind: 'article',
|
2017-02-09 02:36:29 +01:00
|
|
|
academic_year: i.identifier.to_s[/\d\d-\d\d/],
|
2017-02-09 02:31:56 +01:00
|
|
|
created_at: Date.parse(i[:created_at])
|
2017-02-09 02:37:43 +01:00
|
|
|
)
|
2016-12-11 00:55:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-07 10:23:02 +02:00
|
|
|
def create_yearly_items(type)
|
|
|
|
type = type.to_s
|
|
|
|
years = @items.find_all("/#{type.downcase}/*/*").map { |i| i.identifier.to_s[/\d\d-\d\d/] }.uniq
|
|
|
|
|
|
|
|
years.each do |year|
|
2016-12-11 00:55:11 +01:00
|
|
|
@items.create(
|
|
|
|
'',
|
2017-06-07 10:23:02 +02:00
|
|
|
{ academic_year: year, title: type },
|
|
|
|
"/#{type.downcase}/#{year}.html"
|
2016-12-11 00:55:11 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-06-14 09:09:37 +02:00
|
|
|
cur_year_item = @items["/#{type.downcase}/#{@config[:academic_year]}.html"] || @items["/#{type.downcase}/#{years[-1]}.html"]
|
|
|
|
cur_year_item.update_attributes(
|
2016-12-11 00:55:11 +01:00
|
|
|
navigable: true,
|
|
|
|
order: 10
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def convert_event_time_to_timestamps
|
2017-10-03 14:07:39 +02:00
|
|
|
@items.find_all('/events/*/*.md').each do |event|
|
|
|
|
# HACK: Strings in a format like "2017-10-05T20:45:00+0200" automatically get converted to Time
|
|
|
|
|
|
|
|
event[:time] = event[:time].to_s
|
2016-12-11 00:55:11 +01:00
|
|
|
event[:time] = DateTime.parse(event[:time])
|
2017-10-03 14:07:39 +02:00
|
|
|
|
|
|
|
event[:end] = event[:end].to_s if event[:end]
|
2017-02-08 17:05:48 +01:00
|
|
|
event[:end] = DateTime.parse(event[:end]) if event[:end]
|
2016-12-11 00:55:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|