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
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
module TimeHelper
|
module TimeHelper
|
||||||
def christmastime?
|
def christmastime?
|
||||||
timehelper([[Time.new(Time.now.year,12,6),Time.new(Time.now.year,12,31)]])
|
timehelper([[Time.new(Time.now.year, 12, 6), Time.new(Time.now.year, 12, 31)]])
|
||||||
end
|
end
|
||||||
|
|
||||||
def studytime?
|
def studytime?
|
||||||
year = Time.now.year
|
year = Time.now.year
|
||||||
timehelper([
|
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
|
||||||
|
|
||||||
def timehelper(ranges)
|
def timehelper(ranges)
|
||||||
ranges.any? {|range| periodhelper(*range)}
|
ranges.any? { |range| periodhelper(*range) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def periodhelper(startdate, enddate)
|
def periodhelper(startdate, enddate)
|
||||||
|
|
Loading…
Reference in a new issue