add ical support'

This commit is contained in:
Lorin Werthen 2016-07-27 00:13:36 +02:00
parent 73f6279f2f
commit 8448436a46
No known key found for this signature in database
GPG key ID: F11FFC921E0E08E0
8 changed files with 52 additions and 0 deletions

View file

@ -13,6 +13,9 @@ gem 'builder'
# Checks
gem 'w3c_validators'
# ical files
gem 'icalendar'
group :development do
gem 'adsf'
gem 'guard-nanoc'

View file

@ -32,6 +32,7 @@ GEM
nanoc (~> 4.0)
hamster (3.0.0)
concurrent-ruby (~> 1.0)
icalendar (2.4.0)
json (2.0.1)
kramdown (1.11.1)
listen (3.1.5)
@ -79,6 +80,7 @@ DEPENDENCIES
builder
coffee-script
guard-nanoc
icalendar
kramdown
nanoc (= 4.2.4)
nokogiri

18
Rules
View file

@ -2,6 +2,7 @@
# frozen_string_literal: true
require 'json'
require 'icalendar'
#
#
@ -83,6 +84,10 @@ compile '/posts/**/*', rep: :text do
filter :strip_html
end
compile '/posts/**/*', rep: :ical do
filter :ical
end
#
# GENERIC ERB PAGES
#
@ -90,6 +95,10 @@ compile '/tipuesearch_content.js.erb' do
filter :erb
end
compile '/**/*.ics.erb' do
filter :erb
end
compile '/*.erb' do
layout '/generic.*'
layout '/default.*'
@ -142,6 +151,15 @@ route '/assets/scripts/**/*' do
end
# TEXT
route '/*.ics.erb' do
item.identifier.without_ext
end
# POSTS
route '/posts/**/*', rep: :ical do
"#{item.identifier.without_ext}.ics"
end
route '/**/*.{erb,html,md}' do
"#{item.identifier.without_ext}/index.html"
end

1
content/ical.ics.erb Normal file
View file

@ -0,0 +1 @@
<%= event_calendar %>

View file

@ -0,0 +1,9 @@
class IcalFilter < Nanoc::Filter
identifier :ical
def run(_content, _params = {})
cal = Icalendar::Calendar.new
cal.add_event(event_for(item))
cal.to_ical
end
end

18
lib/helpers/ical.rb Normal file
View file

@ -0,0 +1,18 @@
module IcalHelper
def event_calendar
cal = Icalendar::Calendar.new
events = items.find_all('/posts/**/*').map { |i| event_for(i) }
events.each { |e| cal.add_event(e) }
cal.to_ical
end
def event_for(i)
event = Icalendar::Event.new
event.dtstart = Date.parse(i[:time])
event.summary = 'A great event!'
event
end
end

View file

@ -5,3 +5,4 @@ include Nanoc::Helpers::Rendering
include Nanoc::Helpers::Text
include ArchiveHelper
include IcalHelper