Created
October 25, 2013 19:02
-
-
Save jorgepedret/7160052 to your computer and use it in GitHub Desktop.
Recursive function to create dynamic sitemap of your website in Harp using Jade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- var paths = [], files = []; function recursiveTree(obj) { if (typeof obj == "object" && !obj.length) { for (item in obj) { if (item === "contents") { recursiveTree(obj[item]); } else if (item != "data") { paths.push(item); recursiveTree(obj[item]); paths.splice(paths.length-1, 1); } } } else if (typeof obj == "object") { for (i in obj) { var file = obj[i]; if (/(\.html$)/.test(file)) { paths.push(file); files.push("/" + paths.join("/")); paths.splice(paths.length-1, 1); } } } }; recursiveTree(public); | |
xml | |
urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") | |
- for(i in files) { | |
url | |
loc= files[i] | |
priority 0.5 | |
- } |
much better...
mixin tree(head, tail)
for val, key in head
if key !== '.git' && key !== 'data'
if key == 'contents'
each file in val
p= tail + file
else
mixin tree(val, tail + key + "/")
h1 Sitemap
mixin tree(public, "/")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call from any template...
_tree.jade