add ical support'
This commit is contained in:
parent
73f6279f2f
commit
8448436a46
8 changed files with 52 additions and 0 deletions
3
Gemfile
3
Gemfile
|
@ -13,6 +13,9 @@ gem 'builder'
|
|||
# Checks
|
||||
gem 'w3c_validators'
|
||||
|
||||
# ical files
|
||||
gem 'icalendar'
|
||||
|
||||
group :development do
|
||||
gem 'adsf'
|
||||
gem 'guard-nanoc'
|
||||
|
|
|
@ -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
18
Rules
|
@ -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
1
content/ical.ics.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= event_calendar %>
|
9
lib/filters/ical_filter.rb
Normal file
9
lib/filters/ical_filter.rb
Normal 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
18
lib/helpers/ical.rb
Normal 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
|
|
@ -5,3 +5,4 @@ include Nanoc::Helpers::Rendering
|
|||
include Nanoc::Helpers::Text
|
||||
|
||||
include ArchiveHelper
|
||||
include IcalHelper
|
Loading…
Reference in a new issue