some code cleanup

This commit is contained in:
Lorin Werthen 2017-02-09 02:31:56 +01:00
parent ea9ba4f559
commit 7e3c2d5a6c
No known key found for this signature in database
GPG key ID: F11FFC921E0E08E0
4 changed files with 19 additions and 26 deletions

View file

@ -1,26 +1,18 @@
module ArchiveHelper module ArchiveHelper
def academic_years def academic_years
academic_years = Set.new Set.new(items.find_all('/blog/*/*').map { |i| i.identifier.to_s[/\d\d-\d\d/] }).to_a
items.find_all('/blog/*/*').each do |i|
academic_year = %r{/(\d\d)-\d\d/}.match(i.identifier).captures[0]
academic_years << academic_year.to_i
end
academic_years
end end
def academic_years_items def academic_years_items
academic_years.to_a.reverse.map { |y| [y, items["/blog/#{y}-#{y + 1}.html"]] }.to_h academic_years.reverse.map { |y| [y, items["/blog/#{y}.html"]] }
end end
def pretty_year(year) def pretty_year(year)
"'#{year} - '#{year + 1}" year = year.scan(/\d\d/)
"'#{year[0]} - '#{year[1]}"
end end
def posts_in_year(academic_year) def posts_in_year(y)
items.find_all('/blog/*/*').sort_by { |x| Date.parse x[:created_at] }.select do |post| items.find_all("/blog/#{y}/*").sort_by { |x| x[:created_at] }.reverse
post[:academic_year] == academic_year
end.reverse
end end
end end

View file

@ -3,7 +3,7 @@ require 'words_counted'
module BlogHelper module BlogHelper
def reading_time(blogpost) def reading_time(blogpost)
human_wpm = 200.0 human_wpm = 200.0
words = WordsCounted.count(blogpost.reps[:text].compiled_content).token_count words = WordsCounted.count(blogpost.compiled_content(rep: :text)).token_count
minutes = (words / human_wpm).ceil minutes = (words / human_wpm).ceil

View file

@ -8,12 +8,13 @@ module PreprocessHelper
def update_blog_attributes def update_blog_attributes
@items.find_all('/blog/**/*').each do |i| @items.find_all('/blog/**/*').each do |i|
year_str = %r{/(\d\d)-\d\d/}.match(i.identifier).captures[0] year_str = %r{/(\d\d-\d\d)/}.match(i.identifier).captures[0]
attr_hash = { attr_hash = {
# Tag all posts with article (for Blogging helper) # Tag all posts with article (for Blogging helper)
kind: 'article', kind: 'article',
academic_year: year_str.to_i academic_year: year_str,
created_at: Date.parse(i[:created_at])
} }
i.update_attributes(attr_hash) i.update_attributes(attr_hash)
@ -26,11 +27,11 @@ module PreprocessHelper
@items.create( @items.create(
'', '',
{ academic_year: year, title: 'Blog' }, { academic_year: year, title: 'Blog' },
"/blog/#{year}-#{year + 1}.html" "/blog/#{year}.html"
) )
end end
academic_years_items[academic_years.max].update_attributes( academic_years_items[0][1].update_attributes(
navigable: true, navigable: true,
order: 10 order: 10
) )

View file

@ -9,7 +9,7 @@ module TimeHelper
[Time.new(year, 12, 14), Time.new(year, 12, 31)], [Time.new(year, 12, 14), Time.new(year, 12, 31)],
[Time.new(year, 1, 1), Time.new(year, 2, 7)], [Time.new(year, 1, 1), Time.new(year, 2, 7)],
[Time.new(year, 5, 15), Time.new(year, 6, 30)], [Time.new(year, 5, 15), Time.new(year, 6, 30)],
[Time.new(year,8,5), Time.new(year,9,10)], [Time.new(year, 8, 5), Time.new(year, 9, 10)]
]) ])
end end