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

49 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2016-07-23 19:17:24 +00:00
module ArchiveHelper
def academic_years
# Set.to_a to prevent duplicates
Set.new(items
.find_all('/blog/*/*')
2020-10-12 17:40:15 +00:00
.map { |i| i.identifier.to_s.split('/')[-2] })
.to_a
.sort
.push(@config[:academic_year])
.uniq
2016-07-23 19:17:24 +00:00
end
def academic_years_blog_items
2017-02-09 01:31:56 +00:00
academic_years.reverse.map { |y| [y, items["/blog/#{y}.html"]] }
2016-07-23 19:17:24 +00:00
end
2020-10-12 17:40:15 +00:00
def tag_blog_items
2020-10-13 10:01:47 +00:00
Set.new(items
.find_all('/blog/*/*')
.flat_map { |i| i[:tags] || [] })
.to_a
.sort
.uniq.map { |y| [y, items["/blog/#{y.gsub(' ', '_')}.html"]]}
2020-10-12 17:40:15 +00:00
end
2016-07-23 20:06:06 +00:00
def pretty_year(year)
2017-02-09 01:31:56 +00:00
year = year.scan(/\d\d/)
"'#{year[0]} - '#{year[1]}"
2016-07-23 20:06:06 +00:00
end
2017-02-09 01:31:56 +00:00
def posts_in_year(y)
items.find_all("/blog/#{y}/*").sort_by { |x| x[:created_at] }.reverse
2016-07-23 19:17:24 +00:00
end
2020-10-12 17:40:15 +00:00
def posts_with_tag(tag)
items
.find_all('/blog/*/*')
.filter{|i| (i[:tags] || []).include? tag }
end
def posts_in_year_or_with_tag(item)
if item[:is_yearly]
posts_in_year(item[:academic_year])
else
posts_with_tag(item[:tag])
end
end
2016-07-23 19:17:24 +00:00
end