Merge pull request #210 from audionerd/master
new page features useful for sitemap traversal
This commit is contained in:
commit
2e0467650e
|
@ -54,3 +54,20 @@ Feature: Step through sitemap as a tree
|
||||||
Given the Server is running at "traversal-app"
|
Given the Server is running at "traversal-app"
|
||||||
When I go to "/sub/fake.html"
|
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/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,0 +1,3 @@
|
||||||
|
---
|
||||||
|
title: Title of Sibling One
|
||||||
|
---
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
title: Title of Sibling Two
|
||||||
|
---
|
|
@ -11,3 +11,9 @@ Source: <%= current_page.source_file.sub(root + "/", "") %>
|
||||||
<% current_page.siblings.each do |p| %>
|
<% current_page.siblings.each do |p| %>
|
||||||
Sibling: <%= p.path %>
|
Sibling: <%= p.path %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% current_page.children.each do |p| %>
|
||||||
|
<% if p.data %>
|
||||||
|
Data: <%= p.data %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
|
@ -99,10 +99,32 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def directory_index?
|
def directory_index?
|
||||||
path.include?(app.index_file) || path =~ /\/$/
|
path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory?
|
||||||
end
|
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
|
def parent
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
if path.include?(app.index_file)
|
if path.include?(app.index_file)
|
||||||
|
@ -127,16 +149,21 @@ module Middleman::Sitemap
|
||||||
def children
|
def children
|
||||||
return [] unless directory_index?
|
return [] unless directory_index?
|
||||||
|
|
||||||
|
if eponymous_directory?
|
||||||
|
base_path = eponymous_directory_path
|
||||||
|
prefix = /^#{base_path.sub("/", "\\/")}/
|
||||||
|
else
|
||||||
base_path = path.sub("#{app.index_file}", "")
|
base_path = path.sub("#{app.index_file}", "")
|
||||||
prefix = /^#{base_path.sub("/", "\\/")}/
|
prefix = /^#{base_path.sub("/", "\\/")}/
|
||||||
|
end
|
||||||
|
|
||||||
store.all_paths.select do |sub_path|
|
store.all_paths.select do |sub_path|
|
||||||
sub_path =~ prefix
|
sub_path =~ prefix
|
||||||
end.select do |sub_path|
|
end.select do |sub_path|
|
||||||
path != sub_path
|
path != sub_path
|
||||||
end.select do |sub_path|
|
end.select do |sub_path|
|
||||||
relative_path = sub_path.sub(prefix, "")
|
inner_path = sub_path.sub(prefix, "")
|
||||||
parts = relative_path.split("/")
|
parts = inner_path.split("/")
|
||||||
if parts.length == 1
|
if parts.length == 1
|
||||||
true
|
true
|
||||||
elsif parts.length == 2
|
elsif parts.length == 2
|
||||||
|
|
Loading…
Reference in a new issue