1
0
Fork 0
mirror of https://github.com/fmap/muflax65ngodyewp.onion synced 2024-07-03 11:00:42 +02:00
muflax65ngodyewp.onion/lib/default.rb
muflax ac102f8cfa * auto-generate categories, references
* clean-up
* basic 404 page
* alternative titles
* don't show comments in html
2011-09-03 14:28:45 +02:00

72 lines
1.3 KiB
Ruby

# Helper functions for site-building.
include Nanoc3::Helpers::Breadcrumbs
class Nanoc3::Item
def add_content content
@raw_content += "\n\n#{content}"
end
def add_references refs
add_content refs
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