move Sitemap into application, it's core to the entire system
This commit is contained in:
parent
3a2cab4775
commit
3a19cc668d
3 changed files with 33 additions and 53 deletions
|
@ -15,7 +15,6 @@ require 'hooks'
|
|||
# Our custom logger
|
||||
require 'middleman-core/logger'
|
||||
|
||||
require 'middleman-core/sitemap'
|
||||
require 'middleman-core/sitemap/store'
|
||||
|
||||
require 'middleman-core/configuration'
|
||||
|
@ -134,6 +133,27 @@ module Middleman
|
|||
# @return [Boolean]
|
||||
config.define_setting :protect_from_csrf, false, 'Should Padrino include CRSF tag'
|
||||
|
||||
# Set to automatically convert some characters into a directory
|
||||
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
|
||||
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
|
||||
partials: proc { |file| file =~ %r{/_[^_]} },
|
||||
|
||||
layout: proc { |file, sitemap_app|
|
||||
file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/'))
|
||||
}
|
||||
}, 'Callbacks that can exclude paths from the sitemap'
|
||||
|
||||
# Activate custom features and extensions
|
||||
include Middleman::CoreExtensions::Extensions
|
||||
|
||||
|
@ -143,9 +163,6 @@ module Middleman
|
|||
# Setup custom rendering
|
||||
include Middleman::CoreExtensions::Rendering
|
||||
|
||||
# Sitemap Config options and public api
|
||||
include Middleman::Sitemap
|
||||
|
||||
# Reference to Logger singleton
|
||||
def logger
|
||||
::Middleman::Logger.singleton
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
# Core Sitemap Extensions
|
||||
module Middleman
|
||||
module Sitemap
|
||||
# Setup Extension
|
||||
class << self
|
||||
# Once registered
|
||||
def included(app)
|
||||
# Set to automatically convert some characters into a directory
|
||||
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
|
||||
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
|
||||
partials: proc { |file| file =~ %r{/_[^_]} },
|
||||
|
||||
layout: proc { |file, sitemap_app|
|
||||
file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/'))
|
||||
}
|
||||
}, 'Callbacks that can exclude paths from the sitemap'
|
||||
|
||||
# Include instance methods
|
||||
::Middleman::TemplateContext.send :include, InstanceMethods
|
||||
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_resource
|
||||
return nil unless current_path
|
||||
sitemap.find_resource_by_destination_path(current_path)
|
||||
end
|
||||
alias_method :current_page, :current_resource
|
||||
end
|
||||
end
|
||||
end
|
|
@ -154,5 +154,17 @@ module Middleman
|
|||
file_renderer = ::Middleman::FileRenderer.new(@app, path)
|
||||
file_renderer.render(locs, opts, self, &block)
|
||||
end
|
||||
|
||||
def current_path
|
||||
@locs[:current_path]
|
||||
end
|
||||
|
||||
# Get the resource object for the current path
|
||||
# @return [Middleman::Sitemap::Resource]
|
||||
def current_resource
|
||||
return nil unless current_path
|
||||
sitemap.find_resource_by_destination_path(current_path)
|
||||
end
|
||||
alias_method :current_page, :current_resource
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue