zeus.ugent.be/lib/helpers/preprocess.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2016-12-10 23:55:11 +00:00
module PreprocessHelper
def ignore_old_blogposts
@items.delete_if do |item|
next unless item.identifier.to_s.start_with?('/blog/')
!item.identifier.to_s.start_with?('/blog/16-17/')
end
end
def update_blog_attributes
@items.find_all('/blog/**/*').each do |i|
2017-05-03 21:08:15 +00:00
raise "#{i.identifier} doesn't have 'created_at'" unless i[:created_at]
2017-02-09 01:37:43 +00:00
i.update_attributes(
2016-12-10 23:55:11 +00:00
# Tag all posts with article (for Blogging helper)
kind: 'article',
2017-02-09 01:36:29 +00:00
academic_year: i.identifier.to_s[/\d\d-\d\d/],
2017-02-09 01:31:56 +00:00
created_at: Date.parse(i[:created_at])
2017-02-09 01:37:43 +00:00
)
2016-12-10 23:55:11 +00:00
end
end
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-10 23:55:11 +00:00
@items.create(
'',
{ academic_year: year, title: type },
"/#{type.downcase}/#{year}.html"
2016-12-10 23:55:11 +00:00
)
end
@items["/#{type.downcase}/#{years[-1]}.html"].update_attributes(
2016-12-10 23:55:11 +00:00
navigable: true,
order: 10
)
end
def convert_event_time_to_timestamps
all_events.each do |event|
event[:time] = DateTime.parse(event[:time])
2017-02-08 16:05:48 +00:00
event[:end] = DateTime.parse(event[:end]) if event[:end]
2016-12-10 23:55:11 +00:00
end
end
end