2012-04-04 19:26:07 +02:00
|
|
|
# Core Sitemap Extensions
|
2012-05-07 23:41:39 +02:00
|
|
|
module Middleman
|
|
|
|
module Sitemap
|
|
|
|
# Setup Extension
|
|
|
|
class << self
|
|
|
|
# Once registered
|
2014-01-01 23:50:42 +01:00
|
|
|
def included(app)
|
2012-06-20 05:07:50 +02:00
|
|
|
# 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'
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-07 23:41:39 +02:00
|
|
|
# Setup callbacks which can exclude paths from the sitemap
|
2012-10-14 04:54:55 +02:00
|
|
|
app.config.define_setting :ignored_sitemap_matchers, {
|
2012-05-07 23:41:39 +02:00
|
|
|
# dotfiles and folders in the root
|
2014-04-29 19:50:21 +02:00
|
|
|
root_dotfiles: proc { |file| file.start_with?('.') },
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-07 23:41:39 +02:00
|
|
|
# Files starting with an dot, but not .htaccess
|
2014-04-29 19:50:21 +02:00
|
|
|
source_dotfiles: proc { |file|
|
2013-07-01 00:46:39 +02:00
|
|
|
file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd|nojekyll)}
|
2012-05-07 23:41:39 +02:00
|
|
|
},
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-07 23:41:39 +02:00
|
|
|
# Files starting with an underscore, but not a double-underscore
|
2014-04-29 19:50:21 +02:00
|
|
|
partials: proc { |file| file =~ %r{/_[^_]} },
|
2012-08-14 00:39:06 +02:00
|
|
|
|
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-07-19 10:17:50 +02:00
|
|
|
}
|
2012-10-14 04:54:55 +02:00
|
|
|
}, 'Callbacks that can exclude paths from the sitemap'
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-07 23:41:39 +02:00
|
|
|
# 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
|
2012-05-07 23:41:39 +02:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-07 23:41:39 +02:00
|
|
|
# Sitemap instance methods
|
|
|
|
module InstanceMethods
|
2014-01-03 23:56:16 +01:00
|
|
|
def current_path
|
2014-05-25 04:59:21 +02:00
|
|
|
@locs[:current_path]
|
2014-01-03 23:56:16 +01:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-07 23:41:39 +02:00
|
|
|
# Get the resource object for the current path
|
|
|
|
# @return [Middleman::Sitemap::Resource]
|
|
|
|
def current_page
|
|
|
|
current_resource
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-07 23:41:39 +02:00
|
|
|
# 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
|
2012-05-07 23:41:39 +02:00
|
|
|
sitemap.find_resource_by_destination_path(current_path)
|
|
|
|
end
|
|
|
|
end
|
2012-04-04 19:26:07 +02:00
|
|
|
end
|
2012-07-19 10:17:50 +02:00
|
|
|
end
|