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

55 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
2014-04-29 19:50:21 +02:00
root_dotfiles: proc { |file| file.start_with?('.') },
# Files starting with an dot, but not .htaccess
2014-04-29 19:50:21 +02:00
source_dotfiles: proc { |file|
file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd|nojekyll)}
},
# Files starting with an underscore, but not a double-underscore
2014-04-29 19:50:21 +02:00
partials: proc { |file| file =~ %r{/_[^_]} },
2014-04-29 19:44:24 +02:00
layout: proc { |file, sitemap_app|
2014-04-29 01:02:18 +02:00
file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_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
@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