Reputation: 7353
I have the following posts in my blog :
src/documents/posts/foo.html.md
---
category: cooking
---
src/documents/posts/bar.html.md
---
category: programmation
---
I would like to generate the following routes :
http://example.org/cooking/
http://example.org/programmation/
Where each route would have a collection with only posts in the selected category. The posts would still be in the standard place :
http://example.org/posts/foo.html
http://example.org/posts/bar.html
Bonus point : I would also like to be able to list categories in my layout. Something like :
<% for cat in @getCategories() %>
<a href="<%= cat.route %>"><%= cat.name %></a>
<% endfor %>
Is there a plugin already existing which give these kind of functionalities ? If not, what's the best way to starting implementing it ?
I have seen the setFilter
method in this answer, but I'm still struggling to find out how to generate new pages after parsing every posts to fetch categories.
If dynamic page generation cannot be achieved (which I could understand, since it would require to parse pages in a specific order), would having a static array in the configuration make it easier ?
Upvotes: 1
Views: 230
Reputation: 21
I was able to do this same thing with a tags plug-in: https://github.com/rantecki/docpad-plugin-tagging
It automagically creates views for each tag you use. Listing the categories is pretty simple as well. Here's what I've got, using a select box:
<select ONCHANGE="location = this.options[this.selectedIndex].value;">
<option value="">Choose</option>
<% for tag, data of @getTagCloud(): %>
<option value="<%= data.url %>">
<%= tag %>
</option>
<% end %>
</select>
Upvotes: 0
Reputation: 10167
Have a look at this related plugin :
https://github.com/docpad/docpad-plugin-related
As far as I know it doesn't generate tags pages automatically for you, but that's a good start.
Upvotes: 1