sitemap_tree helper
This commit is contained in:
parent
ce841ccd18
commit
e8d50ad204
3 changed files with 39 additions and 2 deletions
|
@ -150,6 +150,9 @@ module Middleman
|
||||||
|
|
||||||
# Automatically convert filename.html files into filename/index.html
|
# Automatically convert filename.html files into filename/index.html
|
||||||
autoload :DirectoryIndexes, "middleman/features/directory_indexes"
|
autoload :DirectoryIndexes, "middleman/features/directory_indexes"
|
||||||
|
|
||||||
|
# Organize the sitemap as a tree
|
||||||
|
autoload :SitemapTree, "middleman/features/sitemap_tree"
|
||||||
end
|
end
|
||||||
|
|
||||||
EXTENSION_FILE = File.join("lib", "middleman_init.rb")
|
EXTENSION_FILE = File.join("lib", "middleman_init.rb")
|
||||||
|
|
|
@ -78,7 +78,8 @@ module Middleman::Base
|
||||||
app.register Middleman::CoreExtensions::FrontMatter
|
app.register Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
app.set :default_features, [
|
app.set :default_features, [
|
||||||
:lorem
|
:lorem,
|
||||||
|
:sitemap_tree
|
||||||
]
|
]
|
||||||
|
|
||||||
# Default layout name
|
# Default layout name
|
||||||
|
|
|
@ -1 +1,34 @@
|
||||||
# Represent the HTML files in the site as a tree
|
module Middleman::Features::SitemapTree
|
||||||
|
class << self
|
||||||
|
def registered(app)
|
||||||
|
app.helpers Helpers
|
||||||
|
end
|
||||||
|
alias :included :registered
|
||||||
|
end
|
||||||
|
|
||||||
|
module Helpers
|
||||||
|
def sitemap_tree(regex=nil)
|
||||||
|
@sitemap_tree_cache = {}
|
||||||
|
|
||||||
|
key = regex.nil? "all" : regex
|
||||||
|
|
||||||
|
if !@sitemap_tree_cache.has_key?(key)
|
||||||
|
auto_hash = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }
|
||||||
|
|
||||||
|
app.sitemap.all_paths.each do |path|
|
||||||
|
next if !regex.nil? && !path.match(regex)
|
||||||
|
sub = auto_hash
|
||||||
|
path.split( "/" ).each{ |dir| sub[dir]; sub = sub[dir] }
|
||||||
|
end
|
||||||
|
|
||||||
|
@sitemap_tree_cache[key] = auto_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
@sitemap_tree_cache[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_sitemap
|
||||||
|
sitemap_tree(/\.html$/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue