module Middleman::Sitemap::Extensions::Traversal

def children

Returns:
  • (Array) -
def children
  return [] unless directory_index?
  if eponymous_directory?
    base_path = eponymous_directory_path
    prefix    = %r|^#{base_path.sub("/", "\\/")}|
  else
    base_path = path.sub("#{app.index_file}", "")
    prefix    = %r|^#{base_path.sub("/", "\\/")}|
  end
  store.resources.select do |sub_resource|
    if sub_resource.path == self.path || sub_resource.path !~ prefix
      false
    else
      inner_path = sub_resource.path.sub(prefix, "")
      parts = inner_path.split("/")
      if parts.length == 1
        true
      elsif parts.length == 2
        parts.last == app.index_file
      else
        false
      end
    end
  end
end

def directory_index?

Returns:
  • (Boolean) -
def directory_index?
  path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory?
end

def eponymous_directory?

Returns:
  • (Boolean) -
def eponymous_directory?
  if !path.end_with?("/#{app.index_file}") && destination_path.end_with?("/#{app.index_file}")
    return true
  end
  full_path = File.join(app.source_dir, eponymous_directory_path)
  !!(File.exists?(full_path) && File.directory?(full_path))
end

def eponymous_directory_path

Returns:
  • (String) -
def eponymous_directory_path
  path.sub(ext, '/').sub(/\/$/, "") + "/"
end

def parent

Returns:
  • (Middleman::Sitemap::Resource, nil) -
def parent
  parts = path.split("/")
  parts.pop if path.include?(app.index_file)
  return nil if parts.length < 1
  parts.pop
  parts << app.index_file
  parent_path = "/" + parts.join("/")
  store.find_resource_by_destination_path(parent_path)
end

def siblings

Returns:
  • (Array) -
def siblings
  return [] unless parent
  parent.children.reject { |p| p == self }
end