Merge pull request #210 from audionerd/master
new page features useful for sitemap traversal
This commit is contained in:
commit
2e0467650e
9 changed files with 69 additions and 8 deletions
|
@ -53,4 +53,21 @@ Feature: Step through sitemap as a tree
|
|||
Scenario: Proxied page has source_file
|
||||
Given the Server is running at "traversal-app"
|
||||
When I go to "/sub/fake.html"
|
||||
Then I should see "Source: source/proxied.html.erb"
|
||||
Then I should see "Source: source/proxied.html.erb"
|
||||
|
||||
Scenario: Child pages have data
|
||||
Given the Server is running at "traversal-app"
|
||||
When I go to "/directory-indexed"
|
||||
Then I should see "Title of Sibling One"
|
||||
Then I should see "Title of Sibling Two"
|
||||
|
||||
Scenario: When directory_index extension is active, child pages are found in named directory
|
||||
Given the Server is running at "traversal-app"
|
||||
When I go to "/directory-indexed"
|
||||
Then I should see "Parent: index.html"
|
||||
Then I should see "Child: directory-indexed/fake.html"
|
||||
Then I should see "Child: directory-indexed/fake2.html"
|
||||
Then I should see "Child: directory-indexed/sibling.html"
|
||||
Then I should see "Child: directory-indexed/sibling2.html"
|
||||
Then I should see "Child: directory-indexed/sub2/index.html"
|
||||
Then I should see "Sibling: root.html"
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
activate :directory_indexes
|
||||
|
||||
page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true
|
||||
page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true
|
||||
page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true
|
||||
|
||||
page "/directory-indexed/fake.html", :proxy => "/proxied.html", :ignore => true
|
||||
page "/directory-indexed/fake2.html", :proxy => "/proxied.html", :ignore => true
|
0
fixtures/traversal-app/source/directory-indexed.html.erb
Normal file
0
fixtures/traversal-app/source/directory-indexed.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
title: Title of Sibling One
|
||||
---
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
title: Title of Sibling Two
|
||||
---
|
|
@ -10,4 +10,10 @@ Source: <%= current_page.source_file.sub(root + "/", "") %>
|
|||
|
||||
<% current_page.siblings.each do |p| %>
|
||||
Sibling: <%= p.path %>
|
||||
<% end %>
|
||||
|
||||
<% current_page.children.each do |p| %>
|
||||
<% if p.data %>
|
||||
Data: <%= p.data %>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -99,9 +99,31 @@ module Middleman::Sitemap
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def directory_index?
|
||||
path.include?(app.index_file) || path =~ /\/$/
|
||||
path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory?
|
||||
end
|
||||
|
||||
def eponymous_directory?
|
||||
!!Dir.exists?(File.join(app.source_dir, eponymous_directory_path))
|
||||
end
|
||||
|
||||
def eponymous_directory_path
|
||||
path.sub('.html', '/').sub(/\/$/, "") + "/"
|
||||
end
|
||||
|
||||
def relative_path
|
||||
source_file.sub(app.source_dir, '')
|
||||
end
|
||||
|
||||
def data
|
||||
data, content = app.frontmatter.data(relative_path)
|
||||
data || nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def parent
|
||||
parts = path.split("/")
|
||||
|
@ -126,17 +148,22 @@ module Middleman::Sitemap
|
|||
|
||||
def children
|
||||
return [] unless directory_index?
|
||||
|
||||
base_path = path.sub("#{app.index_file}", "")
|
||||
prefix = /^#{base_path.sub("/", "\\/")}/
|
||||
|
||||
if eponymous_directory?
|
||||
base_path = eponymous_directory_path
|
||||
prefix = /^#{base_path.sub("/", "\\/")}/
|
||||
else
|
||||
base_path = path.sub("#{app.index_file}", "")
|
||||
prefix = /^#{base_path.sub("/", "\\/")}/
|
||||
end
|
||||
|
||||
store.all_paths.select do |sub_path|
|
||||
sub_path =~ prefix
|
||||
end.select do |sub_path|
|
||||
path != sub_path
|
||||
end.select do |sub_path|
|
||||
relative_path = sub_path.sub(prefix, "")
|
||||
parts = relative_path.split("/")
|
||||
inner_path = sub_path.sub(prefix, "")
|
||||
parts = inner_path.split("/")
|
||||
if parts.length == 1
|
||||
true
|
||||
elsif parts.length == 2
|
||||
|
|
Loading…
Reference in a new issue