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

60 lines
1.8 KiB
Ruby
Raw Normal View History

2012-04-04 19:26:07 +02:00
# Core Sitemap Extensions
module Middleman
module Sitemap
# Setup Extension
class << self
# Once registered
2014-01-01 23:50:42 +01:00
def included(app)
# Set to automatically convert some characters into a directory
2012-10-14 04:54:55 +02:00
app.config.define_setting :automatic_directory_matcher, nil, 'Set to automatically convert some characters into a directory'
# Setup callbacks which can exclude paths from the sitemap
2012-10-14 04:54:55 +02:00
app.config.define_setting :ignored_sitemap_matchers, {
# dotfiles and folders in the root
:root_dotfiles => proc { |file| file.start_with?('.') },
# Files starting with an dot, but not .htaccess
:source_dotfiles => proc { |file|
file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd|nojekyll)}
},
# Files starting with an underscore, but not a double-underscore
2013-05-31 06:16:07 +02:00
:partials => proc { |file| file =~ %r{/_[^_]} },
:layout => proc { |file, app|
file.start_with?(File.join(app.config[:source], 'layout.')) || file.start_with?(File.join(app.config[:source], 'layouts/'))
}
2012-10-14 04:54:55 +02:00
}, 'Callbacks that can exclude paths from the sitemap'
# Include instance methods
2014-01-02 06:19:05 +01:00
::Middleman::TemplateContext.send :include, InstanceMethods
2012-04-04 19:26:07 +02:00
end
end
# Sitemap instance methods
module InstanceMethods
def current_path
@current_locs[:current_path]
end
# Get the resource object for the current path
# @return [Middleman::Sitemap::Resource]
def current_page
current_resource
end
# Get the resource object for the current path
# @return [Middleman::Sitemap::Resource]
def current_resource
2013-02-11 02:51:47 +01:00
return nil unless current_path
sitemap.find_resource_by_destination_path(current_path)
end
end
2012-04-04 19:26:07 +02:00
end
end