Framework CCCS page
This commit is contained in:
parent
09aba964a9
commit
8f812ab935
319 changed files with 24165 additions and 50 deletions
4
lib/articlearchive.rb
Normal file
4
lib/articlearchive.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def generate_archive_pages()
|
||||
articles = items.select { |i| i[:kind] == 'article' }
|
||||
generate_yearly_archive(articles, :created_at, '/archives/articles', 'Blogarchiv')
|
||||
end
|
||||
50
lib/articlehelpers.rb
Normal file
50
lib/articlehelpers.rb
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
def article_base_item(item)
|
||||
idparts = item.identifier.split('/')
|
||||
articleid = "/#{idparts[1]}/#{idparts[2]}/"
|
||||
if idparts.length>3 then
|
||||
result = @items[articleid]
|
||||
if (!result)
|
||||
raise Nanoc::Errors::GenericTrivial.new("Base article #{articleid} for item #{item.identifier} not found!")
|
||||
end
|
||||
result
|
||||
else
|
||||
item
|
||||
end
|
||||
end
|
||||
|
||||
def pathname_of_article(item)
|
||||
idparts = item.identifier.split('/')
|
||||
time = item[:created_at]
|
||||
slug = idparts[2].sub( %r{^[0-9]*-}, "" )
|
||||
time.strftime('%Y-%m-%d') + '-' + slug
|
||||
end
|
||||
|
||||
def sanitize_path(path)
|
||||
result = path
|
||||
if (!path.start_with?('/'))
|
||||
result = '/' + result
|
||||
end
|
||||
if (!path.end_with?('/'))
|
||||
result = result + '/'
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def latest_articles(max=nil)
|
||||
@cache_latest_art ||= @site.items.select do |p|
|
||||
p.attributes[:kind] == 'article'
|
||||
end.sort do |a, b|
|
||||
a.attributes[:created_at] <=> b.attributes[:created_at]
|
||||
end.reverse
|
||||
@cache_latest_art[0..(max ? max-1 : @cache_latest_art.length-1)]
|
||||
end
|
||||
|
||||
def latest_articles_referred_to(refers_to, max=nil)
|
||||
refers_to = sanitize_path(refers_to)
|
||||
@site.items.select do |p|
|
||||
p.attributes[:kind]=='article' && p.attributes[:refers_to] && sanitize_path(p.attributes[:refers_to])==refers_to
|
||||
end.sort do |a, b|
|
||||
a.attributes[:created_at] <=> b.attributes[:created_at]
|
||||
end.reverse[0..(max ? max-1 : -1)]
|
||||
end
|
||||
|
||||
16
lib/articlesummary.rb
Normal file
16
lib/articlesummary.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
require 'nokogiri'
|
||||
|
||||
def article_summary(item, separator=/<!-- *more *-->/)
|
||||
# Has intro attribute? Use this
|
||||
if (item[:intro] && item[:intro].length>0)
|
||||
return parse_markdown(item[:intro])
|
||||
end
|
||||
# Try to extract marked teaser from article
|
||||
summary,body = item.compiled_content.split(separator)
|
||||
if (body)
|
||||
return summary
|
||||
end
|
||||
# Else: Extract first top level html element
|
||||
doc = Nokogiri::Slop(item.compiled_content)
|
||||
return doc.children[0].to_html
|
||||
end
|
||||
|
|
@ -2,4 +2,6 @@
|
|||
# before nanoc starts compiling.
|
||||
|
||||
include Nanoc3::Helpers::Rendering
|
||||
include Nanoc::Helpers::HTMLEscape
|
||||
include Nanoc3::Helpers::Blogging
|
||||
|
||||
|
|
|
|||
72
lib/eventhelpers.rb
Normal file
72
lib/eventhelpers.rb
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
def get_events()
|
||||
items.select { |i| (i[:kind]=='event') && i.identifier.start_with?('/events') }
|
||||
end
|
||||
|
||||
def generate_event_pages()
|
||||
articles = get_events()
|
||||
generate_yearly_archive(articles, :startdate, '/events', 'Veranstaltungen des CCC Stuttgart',
|
||||
'event_archive', { :comingtitle => 'Kommende Veranstaltungen', :pasttitle => 'Vergangene Veranstaltungen' })
|
||||
end
|
||||
|
||||
def get_activities()
|
||||
items.select { |i| (i[:kind]=='event') && i.identifier.start_with?('/activities') }
|
||||
end
|
||||
|
||||
def generate_activity_pages()
|
||||
articles = get_activities()
|
||||
generate_yearly_archive(articles, :startdate, '/activities', 'Aktionen und Aktivitäten',
|
||||
'event_archive', { :comingtitle => 'Kommende Aktionen', :pasttitle => 'Vergangene Aktionen' })
|
||||
end
|
||||
|
||||
def get_regulars_tables()
|
||||
items.select { |i| (i[:kind]=='event') && i.identifier.start_with?('/_data/stammtisch/') }
|
||||
end
|
||||
|
||||
def get_public_events()
|
||||
items.select { |i| (i[:kind]=='event') && i[:public] }
|
||||
end
|
||||
|
||||
def calculate_to_date(e)
|
||||
if e[:duration]
|
||||
if e[:startdate].instance_of?(Date)
|
||||
if e[:duration] =~ /(\d+)d/
|
||||
e[:enddate] = e[:startdate] + ($1.to_i - 1)
|
||||
end
|
||||
else
|
||||
if e[:duration] =~ /(\d+)h/
|
||||
e[:enddate] = e[:startdate] + 60*60*$1.to_i
|
||||
end
|
||||
if e[:duration] =~ /(\d+)m/
|
||||
e[:enddate] = e[:startdate] + 60*$1.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def calculate_to_dates()
|
||||
items.select { |i| (i[:kind]=='event') && i[:duration] }.each do |e|
|
||||
calculate_to_date(e)
|
||||
end
|
||||
end
|
||||
|
||||
def conv_tz(t)
|
||||
if (t.utc?)
|
||||
Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
||||
else
|
||||
t
|
||||
end
|
||||
end
|
||||
|
||||
def fix_timezones()
|
||||
items.each do |e|
|
||||
if e[:created_at] && e[:created_at].instance_of?(Time)
|
||||
e[:created_at] = conv_tz(e[:created_at])
|
||||
end
|
||||
if e[:startdate] && e[:startdate].instance_of?(Time)
|
||||
e[:startdate] = conv_tz(e[:startdate])
|
||||
end
|
||||
if e[:enddate] && e[:enddate].instance_of?(Time)
|
||||
e[:enddate] = conv_tz(e[:enddate])
|
||||
end
|
||||
end
|
||||
end
|
||||
12
lib/eventlists.rb
Normal file
12
lib/eventlists.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def expand_event_list(itemId, defaultTitle = nil)
|
||||
@items[itemId][:events].each_with_index do |event,n|
|
||||
metadata = {
|
||||
:title => defaultTitle,
|
||||
:public => true
|
||||
}
|
||||
metadata.merge!(event)
|
||||
metadata[:kind]='event'
|
||||
@items << Nanoc::Item.new("<%= render 'event_body' %>", metadata, "#{itemId}#{n}/")
|
||||
end
|
||||
end
|
||||
|
||||
13
lib/location.rb
Normal file
13
lib/location.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def merge_item_location_data(location, templates)
|
||||
if (location && location[:location])
|
||||
# templates = @items['/_data/locations/'].attributes
|
||||
if templates[location[:location].to_sym]
|
||||
location.merge!(templates[location[:location].to_sym])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def merge_location_data()
|
||||
items.select { |i| i[:kind] == 'event' }.each { |e| merge_item_location_data(e[:location], @items['/_data/locations/'].attributes) }
|
||||
end
|
||||
|
||||
20
lib/menu.rb
Normal file
20
lib/menu.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def path_section(item, n=1)
|
||||
if (n==1 && item.path=='/') then
|
||||
'main'
|
||||
else
|
||||
sections = item.identifier.split('/')
|
||||
if (n<sections.size)
|
||||
sections[n]
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def menu_active_if(ident, n=1, cssclasses='')
|
||||
if (ident==path_section(item, n)) then
|
||||
" class=\"active #{cssclasses}\""
|
||||
else
|
||||
" class=\"#{cssclasses}\""
|
||||
end
|
||||
end
|
||||
9
lib/projectpages.rb
Normal file
9
lib/projectpages.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def projects_by_state()
|
||||
@cache_projects ||= items.select { |i| i[:kind] == 'project' }.sort_by { |i| i[:title] }
|
||||
@cache_projects_by_state ||= @cache_projects.group_by { |item| item[:status] }
|
||||
@cache_projects_by_state
|
||||
end
|
||||
|
||||
def project_id(project)
|
||||
project.identifier.split('/')[2]
|
||||
end
|
||||
11
lib/qrpatch.rb
Normal file
11
lib/qrpatch.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require 'rqrcode_png'
|
||||
|
||||
# Monkey-patch qr generator
|
||||
module RQRCodePNG
|
||||
class Sequence
|
||||
def border_width()
|
||||
# No boundary around image
|
||||
0
|
||||
end
|
||||
end
|
||||
end
|
||||
46
lib/twitter.rb
Normal file
46
lib/twitter.rb
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# encoding: utf-8
|
||||
|
||||
module Nanoc::DataSources::Contrib
|
||||
|
||||
# Fetch data from downloaded twitter csv file
|
||||
class Twitter < Nanoc::DataSource
|
||||
identifier :twitter_file
|
||||
|
||||
def items
|
||||
@items ||= begin
|
||||
require 'csv'
|
||||
|
||||
if @site.config[:twitter_file].nil?
|
||||
raise Nanoc::Errors::GenericTrivial.new('Cannot read Twitter data: site configuration has no twitter_file')
|
||||
end
|
||||
|
||||
# Get data
|
||||
if ! File.exists?(@site.config[:twitter_file])
|
||||
return []
|
||||
end
|
||||
|
||||
# Convert to items
|
||||
@items = []
|
||||
CSV.foreach(@site.config[:twitter_file]) do |row|
|
||||
# Get data
|
||||
content = row[3]
|
||||
attributes = {
|
||||
:kind => 'twitter',
|
||||
:id => row[0],
|
||||
:date => Time.parse(row[1]),
|
||||
:nick => row[2],
|
||||
:url => "https://twitter.com/#{row[2]}/status/#{row[0]}"
|
||||
}
|
||||
identifier = "/_twitter/#{row[0]}/"
|
||||
mtime = Time.parse(row[1])
|
||||
|
||||
# Build item
|
||||
@items += [ Nanoc::Item.new(content, attributes, identifier, mtime) ]
|
||||
end
|
||||
@items
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
53
lib/twitterarchive.rb
Normal file
53
lib/twitterarchive.rb
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
require 'ostruct'
|
||||
|
||||
def split_yearmonth(yearmonth)
|
||||
s = yearmonth.split('-')
|
||||
month = case s[1]
|
||||
when '01'
|
||||
'Januar'
|
||||
when '02'
|
||||
'Februar'
|
||||
when '03'
|
||||
'März'
|
||||
when '04'
|
||||
'April'
|
||||
when '05'
|
||||
'Mai'
|
||||
when '06'
|
||||
'Juni'
|
||||
when '07'
|
||||
'Juli'
|
||||
when '08'
|
||||
'August'
|
||||
when '09'
|
||||
'September'
|
||||
when '10'
|
||||
'Oktober'
|
||||
when '11'
|
||||
'November'
|
||||
when '12'
|
||||
'Dezember'
|
||||
end
|
||||
[ s[1], month, s[0] ]
|
||||
end
|
||||
|
||||
def generate_twitter_archive_pages()
|
||||
monthlist = twitter_grouped_by_month.keys.sort
|
||||
monthlist.each_index { |i|
|
||||
linkprev = if (i>0)
|
||||
", :linkprev => OpenStruct.new(:title => '#{split_yearmonth(monthlist[i-1])[1]} #{split_yearmonth(monthlist[i-1])[2]}', :link => '/archives/twitter/#{monthlist[i-1]}/')"
|
||||
else
|
||||
""
|
||||
end
|
||||
linknext = if (i<monthlist.size-1)
|
||||
", :linknext => OpenStruct.new(:title => '#{split_yearmonth(monthlist[i+1])[1]} #{split_yearmonth(monthlist[i+1])[2]}', :link => '/archives/twitter/#{monthlist[i+1]}/')"
|
||||
else
|
||||
""
|
||||
end
|
||||
@items << Nanoc::Item.new(
|
||||
"<%= render 'twitter_archive', :month => '#{monthlist[i]}' #{linkprev} #{linknext} %>",
|
||||
{ :title => "Twitterarchiv #{split_yearmonth(monthlist[i])[1]} #{split_yearmonth(monthlist[i])[2]}", :kind => "fullpage" },
|
||||
"/archives/twitter/#{monthlist[i]}/")
|
||||
}
|
||||
end
|
||||
|
||||
28
lib/twitterhelpers.rb
Normal file
28
lib/twitterhelpers.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
def twitter_items()
|
||||
@cache_twitter_items ||= items.select { |d| d[:kind] == 'twitter' }
|
||||
@cache_twitter_items
|
||||
end
|
||||
|
||||
def twitter_by_date()
|
||||
@cache_twitter_by_date ||= twitter_items().sort_by { |d| d[:date] }.reverse()
|
||||
@cache_twitter_by_date
|
||||
end
|
||||
|
||||
def twitter_grouped_by_month
|
||||
@cache_twitter_grouped_by_month ||= twitter_by_date().group_by { |d| "#{d[:date].year}-%02d" % d[:date].month }
|
||||
@cache_twitter_grouped_by_month
|
||||
end
|
||||
|
||||
def tweet_to_html(tweet)
|
||||
links = tweet.scan(/https?:\/\/[^ ]*[^ .);:!?]/)
|
||||
result = tweet.dup
|
||||
links.each_with_index do |link,n|
|
||||
result.gsub!(link, "{{{link#{n}}}}")
|
||||
end
|
||||
result = html_escape(result)
|
||||
links.each_with_index do |link,n|
|
||||
result.gsub!("{{{link#{n}}}}", "<a href=\"#{html_escape(link)}\">(Link)</a>")
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
30
lib/yearlyarchive.rb
Normal file
30
lib/yearlyarchive.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
require 'ostruct'
|
||||
|
||||
def generate_yearly_archive(articles, date_attribute, basepath, title, templatename = 'article_archive', attributes = {})
|
||||
today = Time.now
|
||||
currentyear = today.year
|
||||
yearmap = articles.group_by { |item| item[date_attribute].year }
|
||||
if !yearmap.has_key?(currentyear)
|
||||
yearmap[currentyear] = []
|
||||
end
|
||||
yearlist = yearmap.keys.sort
|
||||
yearlist.each_index { |i|
|
||||
year = yearlist[i]
|
||||
yearmap[year].sort! { |a,b| b[date_attribute] <=> a[date_attribute] }
|
||||
pastfuture = yearmap[year].partition { |a| a[date_attribute].to_datetime > today.to_datetime }
|
||||
linkprev = if (i>0)
|
||||
", :linkprev => OpenStruct.new(:title => '#{yearlist[i-1]}', :link => '#{basepath}/#{yearlist[i-1]}/')"
|
||||
else
|
||||
""
|
||||
end
|
||||
linknext = if (i<yearlist.size-1)
|
||||
", :linknext => OpenStruct.new(:title => '#{yearlist[i+1]}', :link => '#{basepath}/#{yearlist[i+1]}/')"
|
||||
else
|
||||
""
|
||||
end
|
||||
@items << Nanoc::Item.new(
|
||||
"<%= render '#{templatename}' #{linkprev} #{linknext} %>",
|
||||
attributes.merge({ :title => "#{title} #{year}", :kind => "page", :futureitems => pastfuture[0], :pastitems => pastfuture[1] }),
|
||||
"#{basepath}/#{year}/")
|
||||
}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue