Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 26eb404f75
Fetching contributors…

Cannot retrieve contributors at this time

147 lines (124 sloc) 3.775 kb
#!/usr/bin/env ruby
# A few helpful tips about the Rules file:
#
# * The order of rules is important: for each item, only the first matching
# rule is applied.
#
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
# “content/about.html”). To select all children, grandchildren, … of an
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
preprocess do
# authors may unpublish items by setting meta attribute publish: false
items.delete_if { |item| item[:publish] == false }
# First, update metadata for every page
add_update_item_attributes
# Create additional pages
create_tag_pages
# Paginate
create_pages
puts "Copy static content..."
copy_static
end
########################################
## Static
compile '/static/*/' do
end
route "/static/*" do
item[:filename].gsub(%r{^content/static/}, "/")
end
########################################
## Blog
route %r{^/articles/[0-9]+-[0-9]+-[0-9]+-.*/} do
item.identifier.gsub(%r{/([0-9]+)-([0-9]+)-([0-9]+)-(.*/)$}, "/\\1/\\2/\\3/\\4") + "index.html"
end
########################################
## General
##
## The filter depends upon the file extension and can be configured using the
## :filter attribute
##
## The layout can be configured with the :layout attribute
compile '*' do
# item[:extension] returns 'html.erb' for multi-dotted filename
# we only want the last one
ext = item[:extension].nil? ? nil : item[:extension].split('.').last
if not @item[:filter].nil?
if @item[:filter].is_a?(Array) then
@item[:filter].each { |f| filter f }
else
filter @item[:filter]
end
elsif ext == "html"
nil
elsif ext == 'erb' || ext.nil?
filter :erb
elsif ext == 'haml'
filter :haml
elsif ext == 'md' || ext == 'markdown'
filter :erb
filter :kramdown
elsif ext == 'scss'
filter :sass, :style => :scss
item[:layout] = "none" unless item[:layout]
elsif ext == 'sass'
filter :sass
item[:layout] = "none" unless item[:layout]
else
raise "Filter is not configured for item #{item.identifier} (#{ext}) in Rules file."
end
item[:layout] = "default" unless item[:layout]
layout item[:layout] unless item[:layout] == "none"
end
## The routing can be customized using the route_#{rep} and route_match_#{rep}
##
## If not specified,
## only the default route is routed to "index.html"
## If route_match is specified,
## route_match is interpreted as a regular expression, matched with the item
## identifier and route is the replacement of this regular expression
## If route starts with '/'
## it is used as the route
## Else
## route is appended to the item identifier and /*/../ patterns are simplified
route "*" do
route = @item["route_#{@rep.name}".to_sym]
if route.nil? then
if @rep.name == :default then
@item.identifier + 'index.html'
else
nil
end
else
route_match = @item["route_match_#{@rep.name}".to_sym]
if route_match.nil? then
if route =~ /^\// then
route
else
oldpath = @item.identifier + route
path = oldpath.gsub(%r{/[^/]+/\.\./}, "/")
while path != oldpath do
oldpath = path
path = path.gsub(%r{/[^/]+/\.\./}, "/")
end
path
end
else
@item.identifier.gsub(Regexp.new(route_match), route)
end
end
end
########################################
## Atom
compile "*", :rep => :atom do
layout "atom"
end
route "*", :rep => :atom do
if @item.paginated? then
@item.identifier + "atom.xml"
end
end
########################################
## Layouts
layout 'atom', :erb
layout '*', :haml, :format => :html5
Jump to Line
Something went wrong with that request. Please try again.