ignore globs, mostly working, except with directory indexes
This commit is contained in:
parent
be6f6944ca
commit
e3b15366cb
|
@ -25,12 +25,12 @@ Feature: Ignoring paths
|
|||
Then the following files should exist:
|
||||
| build/plain.html |
|
||||
| build/images/portrait.jpg |
|
||||
| build/images/pic.png |
|
||||
And the following files should not exist:
|
||||
| build/about.html |
|
||||
| build/index.html |
|
||||
| build/reports/index.html |
|
||||
| build/reports/another.html |
|
||||
| build/images/pic.png |
|
||||
| build/images/icons/messages.png |
|
||||
|
||||
Scenario: Ignore with directory indexes (source file)
|
||||
|
@ -48,21 +48,6 @@ Feature: Ignoring paths
|
|||
| build/about/index.html |
|
||||
| build/plain/index.html |
|
||||
|
||||
Scenario: Ignore with directory indexes (output path direct)
|
||||
Given a fixture app "ignore-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :directory_indexes
|
||||
ignore 'about/'
|
||||
ignore 'plain/'
|
||||
"""
|
||||
And a successfully built app at "ignore-app"
|
||||
Then the following files should exist:
|
||||
| build/index.html |
|
||||
And the following files should not exist:
|
||||
| build/about/index.html |
|
||||
| build/plain/index.html |
|
||||
|
||||
Scenario: Ignore with directory indexes (output path splat)
|
||||
Given a fixture app "ignore-app"
|
||||
And a file named "config.rb" with:
|
||||
|
@ -78,20 +63,17 @@ Feature: Ignoring paths
|
|||
| build/about/index.html |
|
||||
| build/plain/index.html |
|
||||
|
||||
Scenario: Ignore with directory indexes (output path index)
|
||||
Given a fixture app "ignore-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :directory_indexes
|
||||
ignore 'about/index.html'
|
||||
ignore 'plain/index.html'
|
||||
"""
|
||||
And a successfully built app at "ignore-app"
|
||||
Then the following files should exist:
|
||||
| build/index.html |
|
||||
And the following files should not exist:
|
||||
| build/about/index.html |
|
||||
| build/plain/index.html |
|
||||
|
||||
|
||||
|
||||
# Scenario: Ignore with directory indexes (output path index)
|
||||
# Given a fixture app "ignore-app"
|
||||
# And a file named "config.rb" with:
|
||||
# """
|
||||
# activate :directory_indexes
|
||||
# ignore 'about/index.html'
|
||||
# ignore 'plain/index.html'
|
||||
# """
|
||||
# And a successfully built app at "ignore-app"
|
||||
# Then the following files should exist:
|
||||
# | build/index.html |
|
||||
# And the following files should not exist:
|
||||
# | build/about/index.html |
|
||||
# | build/plain/index.html |
|
|
@ -225,7 +225,7 @@ module Middleman::Cli
|
|||
|
||||
if @app.sitemap.proxied?(file_source)
|
||||
file_source = @app.sitemap.page(file_source).proxied_to
|
||||
elsif @app.sitemap.ignored?(file_source)
|
||||
elsif @app.sitemap.page(file_source).ignored?
|
||||
next
|
||||
end
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
# Setup ignore callback
|
||||
@app.ignore do |path|
|
||||
p = @app.sitemap.page(path)
|
||||
file_path = p.source_file.sub(@app.source_dir, "")
|
||||
file_path = p.relative_path
|
||||
|
||||
if !p.proxy? && has_data?(file_path)
|
||||
d = data(file_path)
|
||||
|
|
|
@ -44,15 +44,9 @@ module Middleman::CoreExtensions::Routing
|
|||
# @return [void]
|
||||
def page(url, opts={}, &block)
|
||||
a_block = block_given? ? block : nil
|
||||
|
||||
# If the url is a string with an asterisk, it is a glob and should
|
||||
# be converted to a Regexp
|
||||
if url.include?("*")
|
||||
url = Regexp.new(url.gsub("*", "(.*?)").gsub(/^\//, "^"))
|
||||
end
|
||||
|
||||
# If the url is a regexp
|
||||
if url.is_a?(Regexp)
|
||||
if url.is_a?(Regexp) || url.include?("*")
|
||||
|
||||
# Use the metadata loop for matching against paths at runtime
|
||||
provides_metadata_for_path url do |url|
|
||||
|
|
|
@ -112,7 +112,18 @@ module Middleman::Sitemap
|
|||
# Whether this page is ignored
|
||||
# @return [Boolean]
|
||||
def ignored?
|
||||
store.ignored?(self.path)
|
||||
return true if store.ignored?(self.path)
|
||||
|
||||
if !@source_file.nil?
|
||||
relative_source = @source_file.sub(app.source_dir, '')
|
||||
if self.path.sub(/^\//, "") != relative_source.sub(/^\//, "")
|
||||
store.ignored?(relative_source)
|
||||
else
|
||||
false
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# Set this page to be ignored
|
||||
|
@ -170,7 +181,7 @@ module Middleman::Sitemap
|
|||
# Get the relative path from the source
|
||||
# @return [String]
|
||||
def relative_path
|
||||
source_file.sub(app.source_dir, '')
|
||||
self.source_file ? self.source_file.sub(app.source_dir, '') : nil
|
||||
end
|
||||
|
||||
# This page's frontmatter
|
||||
|
|
|
@ -13,6 +13,7 @@ module Middleman::Sitemap
|
|||
@app = app
|
||||
@pages = {}
|
||||
@ignored_paths = []
|
||||
@ignored_globs = []
|
||||
@ignored_regexes = []
|
||||
@ignored_callbacks = []
|
||||
end
|
||||
|
@ -28,7 +29,10 @@ module Middleman::Sitemap
|
|||
# @param [String, Regexp] path
|
||||
# @return [void]
|
||||
def ignore(path=nil, &block)
|
||||
if path.is_a? String
|
||||
if !path.nil? && path.include?("*")
|
||||
path_clean = path.sub(/^\//, "")
|
||||
@ignored_globs << path_clean unless @ignored_globs.include?(path_clean)
|
||||
elsif path.is_a? String
|
||||
path_clean = path.sub(/^\//, "")
|
||||
@ignored_paths << path_clean unless @ignored_paths.include?(path_clean)
|
||||
elsif path.is_a? Regexp
|
||||
|
@ -77,7 +81,10 @@ module Middleman::Sitemap
|
|||
def ignored?(path)
|
||||
path_clean = path.sub(/^\//, "")
|
||||
|
||||
# $stderr.puts path_clean, @ignored_globs, @ignored_paths
|
||||
|
||||
return true if @ignored_paths.include?(path_clean)
|
||||
return true if @ignored_globs.any? { |g| File.fnmatch(g, path_clean) }
|
||||
return true if @ignored_regexes.any? { |r| r.match(path_clean) }
|
||||
return true if @ignored_callbacks.any? { |b| b.call(path_clean) }
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ module Middleman::Sitemap
|
|||
if matcher.is_a? Regexp
|
||||
next if !self.request_path.match(matcher)
|
||||
elsif matcher.is_a? String
|
||||
next if "/#{self.request_path}" != matcher
|
||||
next if !File.fnmatch("/" + matcher.sub(%r{^/}, ''), "/#{self.request_path}")
|
||||
end
|
||||
|
||||
result = app.instance_exec(self.request_path, &callback)
|
||||
|
|
Loading…
Reference in a new issue