Subtle tweaks

This commit is contained in:
Thomas Reynolds 2015-05-02 22:44:38 -07:00
parent b9f0330869
commit d1211cc089

View file

@ -5,21 +5,18 @@ module Middleman
module Sitemap module Sitemap
module Extensions module Extensions
class OnDisk < Extension class OnDisk < Extension
attr_accessor :waiting_for_ready
def initialize(app, config={}, &block) def initialize(app, config={}, &block)
super super
@file_paths_on_disk = Set.new @file_paths_on_disk = Set.new
scoped_self = self
@waiting_for_ready = true @waiting_for_ready = true
@app.ready do
scoped_self.waiting_for_ready = false
# Make sure the sitemap is ready for the first request
sitemap.ensure_resource_list_updated!
end end
def ready
@waiting_for_ready = false
# Make sure the sitemap is ready for the first request
app.sitemap.ensure_resource_list_updated!
end end
Contract Any Contract Any
@ -27,6 +24,7 @@ module Middleman
app.files.on_change(:source, &method(:update_files)) app.files.on_change(:source, &method(:update_files))
end end
Contract IsA['Middleman::SourceFile'] => Bool
def ignored?(file) def ignored?(file)
@app.config[:ignored_sitemap_matchers].any? do |_, callback| @app.config[:ignored_sitemap_matchers].any? do |_, callback|
callback.call(file, @app) callback.call(file, @app)
@ -48,9 +46,10 @@ module Middleman
# Force sitemap rebuild so the next request is ready to go. # Force sitemap rebuild so the next request is ready to go.
# Skip this during build because the builder will control sitemap refresh. # Skip this during build because the builder will control sitemap refresh.
@app.sitemap.ensure_resource_list_updated! unless waiting_for_ready || @app.build? @app.sitemap.ensure_resource_list_updated! unless @waiting_for_ready || @app.build?
end end
Contract ArrayOf[IsA['Middleman::SourceFile']]
def files_for_sitemap def files_for_sitemap
@app.files.by_type(:source).files.reject(&method(:ignored?)) @app.files.by_type(:source).files.reject(&method(:ignored?))
end end