middleman/middleman-core/lib/middleman-core/sitemap.rb

81 lines
2.4 KiB
Ruby
Raw Normal View History

require "middleman-core/sitemap/store"
require "middleman-core/sitemap/resource"
require "middleman-core/sitemap/extensions/on_disk"
require "middleman-core/sitemap/extensions/proxies"
require "middleman-core/sitemap/extensions/ignores"
2012-04-04 19:26:07 +02:00
# Core Sitemap Extensions
module Middleman
2012-04-04 19:26:07 +02:00
module Sitemap
2012-04-04 19:26:07 +02:00
# Setup Extension
class << self
2012-04-04 19:26:07 +02:00
# Once registered
def registered(app)
2012-04-04 19:26:07 +02:00
app.register Middleman::Sitemap::Extensions::Proxies
app.register Middleman::Sitemap::Extensions::Ignores
2012-04-04 19:26:07 +02:00
# Set to automatically convert some characters into a directory
app.set :automatic_directory_matcher, nil
# Setup callbacks which can exclude paths from the sitemap
app.set :ignored_sitemap_matchers, {
# dotfiles and folders in the root
:root_dotfiles => proc { |file, path| file.match(/^\./) },
2012-04-04 19:26:07 +02:00
# Files starting with an dot, but not .htaccess
:source_dotfiles => proc { |file, path|
(file.match(/\/\./) && !file.match(/\/\.htaccess/))
},
2012-04-04 19:26:07 +02:00
# Files starting with an underscore, but not a double-underscore
:partials => proc { |file, path| (file.match(/\/_/) && !file.match(/\/__/)) },
2012-04-04 19:26:07 +02:00
:layout => proc { |file, path|
file.match(/^source\/layout\./) || file.match(/^source\/layouts\//)
},
2012-04-04 19:26:07 +02:00
# Files without any output extension (layouts, partials)
# :extensionless => proc { |file, path| !path.match(/\./) },
}
2012-04-04 19:26:07 +02:00
# Include instance methods
app.send :include, InstanceMethods
2012-04-04 19:26:07 +02:00
# Initialize Sitemap
app.before_configuration do
sitemap
end
2012-04-04 19:26:07 +02:00
end
alias :included :registered
2012-04-04 19:26:07 +02:00
end
2012-04-04 19:26:07 +02:00
# Sitemap instance methods
module InstanceMethods
2012-04-04 19:26:07 +02:00
# Get the sitemap class instance
# @return [Middleman::Sitemap::Store]
def sitemap
@_sitemap ||= Store.new(self)
end
2012-04-04 19:26:07 +02:00
# Get the resource object for the current path
# @return [Middleman::Sitemap::Resource]
def current_page
current_resource
end
2012-04-04 19:26:07 +02:00
# Get the resource object for the current path
# @return [Middleman::Sitemap::Resource]
def current_resource
sitemap.find_resource_by_destination_path(current_path)
end
2012-04-04 19:26:07 +02:00
end
2012-04-04 19:26:07 +02:00
end
end