zeus.ugent.be/Rules
2016-10-31 12:29:44 +01:00

206 lines
3.1 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
require 'icalendar'
#
#
# PREPROCESS
#
#
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?('/posts/')
!ident.start_with?('/posts/16-17/')
end
end
@items.find_all('/posts/**/*').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
end
#
#
# COMPILATION
#
#
compile '/feed.xml' do
filter :erb
write '/feed.xml'
end
passthrough '/quotes.json'
#
# ARCHIVES
#
compile '/blog/*' do
layout '/archive_page.*'
layout '/generic.*'
layout '/default.*'
filter :erb
end
#
# EVENTS
#
compile '/events/**/*' do
filter :kramdown
layout '/eventpost.*'
layout '/default.*'
filter :erb
end
compile '/events/**/*', rep: :text do
filter :kramdown
filter :strip_html
end
compile '/events/**/main.md', rep: :ical do
end
compile '/events/**/*', rep: :ical do
filter :ical
end
#
# POSTS
#
compile '/posts/**/*' do
layout '/blogpost.md'
filter :kramdown
layout '/blogpost.erb'
layout '/generic.*'
layout '/default.*'
end
compile '/posts/**/*', rep: :text do
filter :kramdown
filter :strip_html
end
#
# PROJECTS
#
compile '/projects/*' do
filter :kramdown
end
# Don't create specific project pages for now
route '/projects/*' do; end
#
# GENERIC ERB PAGES
#
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
layout '/generic.*'
layout '/default.*'
filter :erb
end
#
# ASSETS
#
compile '/assets/scripts/**/*.coffee' do
filter :coffeescript
end
ignore '/assets/stylesheets/includes/**/*'
compile '/assets/stylesheets/**/*.scss' do
filter :sass, syntax: :scss
filter :autoprefixer if production?
end
passthrough '/assets/images/*.{png,svg}'
passthrough '/assets/**/*.js'
#
#
# ROUTES
#
#
#
# ASSETS
#
route '/assets/stylesheets/**/*' do
"#{item.identifier.without_ext}.css"
end
route '/assets/scripts/**/*' do
"#{item.identifier.without_ext}.js"
end
# EVENTS
route '/events/**/*', rep: :ical do
"#{item.identifier.without_ext}.ics"
end
route '/**/*.{erb,html,md}' do
if item.identifier.without_ext.to_s =~ %r{/index$}
"#{item.identifier.without_ext}.html"
else
"#{item.identifier.without_ext}/index.html"
end
end
#
#
# LAYOUTS
#
#
layout '/**/*', :erb