Closed kbsali closed 10 years ago
Sorry, my initial advice was totally off. It should be possible already, though, we’ll put together an example.
@kbsali Sorry it took a bit, here’s a pretty impressive solution from @sintaxi:
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, "/")
I’m going to leave this issue open as we’re still expanding on this for use with manifest files, etc. and it all needs to go into the docs somewhere.
Thanks a lot @kennethormandy I've just blogged about it : http://kevin.saliou.name/posts/2013-10-28-harpjs-adding-a-sitemap.html#.Um57UyghCyo :+1:
No problem, nice writeup. I definitely don’t deserve credit, though, @sintaxi put it all together.
I’m not sure how you approached doing published and unpublished posts, but if you’re just setting posts to published: false
or something similar, I think you should be able to check for that as you iterate through your content. If you’re naming the posts with an underscore at the beginning, then they should be excluded automatically.
@kennethormandy @sintaxi i upgraded to v0.10.0 and was writting a post on how easy the move went, but i'm having an issue with the sitemap snippet, here is the error i'm getting when compiling my project :
{
"source": "Jade",
"dest": "HTML",
"filename": "/.../public/sitemap.xml.jade",
"lineno": 4,
"name": "RangeError",
"message": "Maximum call stack size exceeded",
"stack": "mixin tree(head, tail)\n for val, key in head\n if key !== '.git' && key !== 'data'\n if key == 'contents'\n each file in val\n if /(\\.html$)/.test(file)\n prio = .4\n if /about/.test(tail + file)\n prio = .9\n if /posts/.test(tail + file)\n prio = .7\n if /index/.test(tail + file)\n prio = .6\n url\n loc= site_url + tail + file\n priority= prio\n else\n mixin tree(val, tail + key + \"/\")\n\ndoctype xml\nurlset(xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\")\n mixin tree(public, \"/\")\n"
}
Any hints on how to get this fixed?
thx
@kbsali The update to the original one would be:
mixin tree(head, tail)
for val, key in head
if key !== '_data'
if key == '_contents'
each file in val
p= tail + file
else
mixin tree(val, tail + key + "/")
h1 Sitemap
mixin tree(public, "/")
You shouldn’t need to check for the .
files anymore in v0.10.0, either, so I’ve removed that.
@kennethormandy man that was a quick answer! Awesome, thanks a lot! :+1:
Another example, using JS one-liners inside Jade: sitemap.xml.jade and _shared/deep.jade.
We’ve collected some useful patterns and snippets for Harp in the Harp recipes section. If you’re looking how to make a sitemap, take a look at this sitemap recipe.
It would be nice to be able to generate a sitemap of all the published slugs, or maybe have a global object slugs listing them all