From 44093935275a94af9921fe6f834ac6c2b1c8ca5e Mon Sep 17 00:00:00 2001 From: Lorin Werthen Date: Sun, 11 Dec 2016 00:55:11 +0100 Subject: [PATCH] cleanup --- Rules | 58 +++++---------------------------------- lib/helpers/preprocess.rb | 44 +++++++++++++++++++++++++++++ lib/helpers_.rb | 1 + 3 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 lib/helpers/preprocess.rb diff --git a/Rules b/Rules index 4ed2f84..36603fe 100644 --- a/Rules +++ b/Rules @@ -14,47 +14,10 @@ preprocess do `npm install` # We don't want to compile old blogposts in development - if development? - @items.delete_if do |item| - ident = item.identifier.to_s - - next unless ident.to_s.start_with?('/blog/') - - !ident.start_with?('/blog/16-17/') - end - end - - @items.find_all('/blog/**/*').each do |i| - year_str = %r{/(\d\d)-\d\d/}.match(i.identifier).captures[0] - academic_year = year_str.to_i - - attr_hash = { - # Tag all posts with article (for Blogging helper) - kind: 'article', - academic_year: academic_year - } - - i.update_attributes(attr_hash) - end - - # academic_years is defined in archives.rb - academic_years.each do |year| - @items.create( - '', - { academic_year: year, title: 'Blog' }, - "/blog/#{year}-#{year + 1}.html", - binary: false - ) - end - - academic_years_items[academic_years.max].update_attributes( - navigable: true, - order: 10 - ) - - all_events.each do |event| - event[:time] = DateTime.parse(event[:time]) - end + ignore_old_blogposts if development? + update_blog_attributes + create_blog_items + convert_event_time_to_timestamps end # @@ -67,8 +30,6 @@ compile '/feed.xml' do write '/feed.xml' end -passthrough '/quotes.json' - # # ARCHIVES # @@ -95,9 +56,6 @@ compile '/events/**/*', rep: :text do filter :strip_html end -compile '/events/**/main.md', rep: :ical do -end - compile '/events/**/*', rep: :ical do filter :ical end @@ -135,12 +93,10 @@ route '/projects/*' do; end # compile '/*_search.json' do filter :erb - write @item.identifier.to_s end compile '/**/*.ics' do filter :erb - write @item.identifier.to_s end compile '/**/*.erb' do @@ -163,9 +119,6 @@ compile '/assets/stylesheets/**/*.scss' do filter :autoprefixer if production? end -passthrough '/assets/images/*.{png,svg}' -passthrough '/assets/**/*.js' - # # # ROUTES @@ -196,6 +149,9 @@ route '/**/*.{erb,html,md}' do end end +# Let anything else simply pass through +passthrough '/**/*' + # # # LAYOUTS diff --git a/lib/helpers/preprocess.rb b/lib/helpers/preprocess.rb new file mode 100644 index 0000000..732b3dd --- /dev/null +++ b/lib/helpers/preprocess.rb @@ -0,0 +1,44 @@ +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| + 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 + } + + i.update_attributes(attr_hash) + end + end + + def create_blog_items + # academic_years is defined in archives.rb + academic_years.each do |year| + @items.create( + '', + { academic_year: year, title: 'Blog' }, + "/blog/#{year}-#{year + 1}.html" + ) + end + + academic_years_items[academic_years.max].update_attributes( + navigable: true, + order: 10 + ) + end + + def convert_event_time_to_timestamps + all_events.each do |event| + event[:time] = DateTime.parse(event[:time]) + end + end +end diff --git a/lib/helpers_.rb b/lib/helpers_.rb index e139277..fc9d4dd 100644 --- a/lib/helpers_.rb +++ b/lib/helpers_.rb @@ -15,3 +15,4 @@ include FontAwesomeHelper include ProjectsHelper include SearchHelper include BlogHelper +include PreprocessHelper