1
0
Fork 0
mirror of https://github.com/fmap/muflax65ngodyewp.onion synced 2024-07-04 11:10:41 +02:00
muflax65ngodyewp.onion/lib/default.rb

72 lines
1.3 KiB
Ruby
Raw Normal View History

# Helper functions for site-building.
2011-07-31 22:51:41 +02:00
include Nanoc3::Helpers::Breadcrumbs
class Nanoc3::Item
def add_content content
@raw_content += "\n\n#{content}"
end
2011-07-31 22:51:41 +02:00
def add_references refs
add_content refs
2011-07-31 22:51:41 +02:00
end
def name
identifier.split("/").last
end
end
# print all items in a category, nicely formatted
def category name
output = []
cat_match = %r{^/#{name}/}
# find category index
cat_index = @items.find{|i| i.path.match(cat_match) and i[:is_category]}
# header
output << "# [#{cat_index[:title]}]"
# find items in category
items = @items.select do |i|
( not i.binary? and
not i[:is_category] and
i.path.match cat_match
)
end
# items in nice list
items.each do |i|
output << "- [#{i[:title]}]"
end
# output
output.map{|i| "#{i}\n"}.join
end
# only articles that actually get printed
def printed_items
@items.select do |i|
( not i.identifier.match %r{/(references|style)/} and
not i.binary?
)
end
end
#automatic links for all pages, used by reference file
def page_references
output = []
printed_items.each do |i|
output << "[#{i[:title]}]: #{i.identifier}"
unless i[:alt_titles].nil?
i[:alt_titles].each do |title|
output << "[#{title}]: #{i.identifier}"
end
end
end
# output
output.map{|i| "#{i}\n"}.join
end