some code cleanup
This commit is contained in:
parent
ea9ba4f559
commit
7e3c2d5a6c
4 changed files with 19 additions and 26 deletions
|
@ -1,26 +1,18 @@
|
|||
module ArchiveHelper
|
||||
def academic_years
|
||||
academic_years = Set.new
|
||||
|
||||
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
|
||||
Set.new(items.find_all('/blog/*/*').map { |i| i.identifier.to_s[/\d\d-\d\d/] }).to_a
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def pretty_year(year)
|
||||
"'#{year} - '#{year + 1}"
|
||||
year = year.scan(/\d\d/)
|
||||
"'#{year[0]} - '#{year[1]}"
|
||||
end
|
||||
|
||||
def posts_in_year(academic_year)
|
||||
items.find_all('/blog/*/*').sort_by { |x| Date.parse x[:created_at] }.select do |post|
|
||||
post[:academic_year] == academic_year
|
||||
end.reverse
|
||||
def posts_in_year(y)
|
||||
items.find_all("/blog/#{y}/*").sort_by { |x| x[:created_at] }.reverse
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'words_counted'
|
|||
module BlogHelper
|
||||
def reading_time(blogpost)
|
||||
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
|
||||
|
||||
|
|
|
@ -8,12 +8,13 @@ module PreprocessHelper
|
|||
|
||||
def update_blog_attributes
|
||||
@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 = {
|
||||
# Tag all posts with article (for Blogging helper)
|
||||
kind: 'article',
|
||||
academic_year: year_str.to_i
|
||||
academic_year: year_str,
|
||||
created_at: Date.parse(i[:created_at])
|
||||
}
|
||||
|
||||
i.update_attributes(attr_hash)
|
||||
|
@ -26,11 +27,11 @@ module PreprocessHelper
|
|||
@items.create(
|
||||
'',
|
||||
{ academic_year: year, title: 'Blog' },
|
||||
"/blog/#{year}-#{year + 1}.html"
|
||||
"/blog/#{year}.html"
|
||||
)
|
||||
end
|
||||
|
||||
academic_years_items[academic_years.max].update_attributes(
|
||||
academic_years_items[0][1].update_attributes(
|
||||
navigable: true,
|
||||
order: 10
|
||||
)
|
||||
|
|
|
@ -9,7 +9,7 @@ module TimeHelper
|
|||
[Time.new(year, 12, 14), Time.new(year, 12, 31)],
|
||||
[Time.new(year, 1, 1), Time.new(year, 2, 7)],
|
||||
[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
|
||||
|
||||
|
|
Loading…
Reference in a new issue