Only including a subset of the generated menu structure
I'm currently evaluating DocPad and came across your plugin and emmet doc sample site. This looks like it works well for a single product documentation site but I have an additional need and I was wondering if this is already a feature I haven't found or something that could be added.
I want to structure my folders under the root with a folder for each product, each product would have subfolders that would be considered topics with the index.html document being the page for the topic. Also in that same topic subfolder I would have additional documents that would show as leafs for the topic.
Something like this:
- Product 1
- Topic 1
- Index.html - (would be page linked to Topic)
- Topic Page1.html
- Topic Page2.html
- Topic Page3.html
- Topic 2
- Index.html - (would be page linked to Topic)
- Topic Page1.html
- Topic Page2.html
- Topic Page3.html
- Topic 1
- Product 2
- Topic 1
- Index.html - (would be page linked to Topic)
- Topic Page1.html
- Topic Page2.html
- Topic Page3.html
- Topic 2
- Index.html - (would be page linked to Topic)
- Topic Page1.html
- Topic Page2.html
- Topic Page3.html etc.
- Topic 1
Then in each of the pages within a Product, I'd like to show only the menu items that exist within that Product. I guess in the template you'd have to pass in the second level folder name and limit only urls that are below that.
I hope this makes sense.
I don’t quite understand what you’re trying to do.
If you want to extract only a subset of menu, you can base URL to generateMenu() template data method, e.g. generateMenu('/product1/topic1/')
Ok, I'll try and explain with an example from http://docs.emmet.io/
In those docs there are a bunch of main sections (Abbreviations, CSS Abbreviations, Actions etc). When I click on the Abbreviations page you still get the full menu. What I'd like to do would be to limit the menu on the Abbreviations page to just those pages that are below that page such as Syntax, Element types, ... but not see the whole menu each time. Does that make more sense?
I also tried doing as you suggested with the generateMenu call in my layout and it still generates the whole menu for every page.
You can simply check state property of menu items to decide if it should be rendered or not: https://github.com/sergeche/docpad-plugin-menu#how-it-works
@sergeche you mean to check the property against the value "parent" ? But with that information you can only find out the parents, not the children, it's the reverse case.
@redwards1966 your explanation from your inital post is very clear to me. I've solved it with a custom collection.
define some collections in your docpad.coffee with a filter for the files via the relativeOutDirPath property - like here: http://stackoverflow.com/questions/15494422/collection-to-be-generated-from-all-the-sub-folders-into-one/15515598#15515598
to use it with the menu plugin, pass the collection name as second parameter @generateMenu(@document.url, "myCustomCollection") (see docs)
My solution was allow the collection instance to be passed in, which means the collection doesn't have to be a named collection listed in the docpad.coffee. That means you can do things like filter the menu items based on the relativeOutDirPath of the current document, in order to obtain automatic product/topic submenus.
@timaschew you can find element with state == "parent" and render its children only