{"action":"created","issue":{"url":"https://api.github.com/repos/assemble/assemble/issues/645","labels_url":"https://api.github.com/repos/assemble/assemble/issues/645/labels{/name}","comments_url":"https://api.github.com/repos/assemble/assemble/issues/645/comments","events_url":"https://api.github.com/repos/assemble/assemble/issues/645/events","html_url":"https://github.com/assemble/assemble/issues/645","id":58521152,"number":645,"title":"v0.6.0 Item ID defaults, renameKey function","user":{"login":"agross","id":16245,"avatar_url":"https://avatars.githubusercontent.com/u/16245?v=3","gravatar_id":"","url":"https://api.github.com/users/agross","html_url":"https://github.com/agross","followers_url":"https://api.github.com/users/agross/followers","following_url":"https://api.github.com/users/agross/following{/other_user}","gists_url":"https://api.github.com/users/agross/gists{/gist_id}","starred_url":"https://api.github.com/users/agross/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agross/subscriptions","organizations_url":"https://api.github.com/users/agross/orgs","repos_url":"https://api.github.com/users/agross/repos","events_url":"https://api.github.com/users/agross/events{/privacy}","received_events_url":"https://api.github.com/users/agross/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-22T21:43:03Z","updated_at":"2015-02-23T16:13:41Z","closed_at":null,"body":"Copied from https://github.com/assemble/assemble/issues/639#issuecomment-75457808:\r\n> As my product JSONs may contain duplicate file names in several subdirectories, I need to define a custom renameKey function. (Related: #619) I'd argue this is a very strange design decision. As least it doesn't make your users fall into the Pit Of Success™. Even a simple\r\n```js\r\nassemble.page('one.hbs', { content: 'one' });\r\nassemble.page('blah/one.hbs', { content: 'blah/one' });\r\n```\r\n> will result in just one page rendered.\r\n\r\n>> Well, we need to match up data with templates correctly.\r\n\r\nWhat do you mean by \"match up data\"? Are you talking about files without front matter metadata, e.g. external metadata?\r\n\r\n>> So if you, as a user, want to have multiple templates with the same name, and you expect assemble to magically know which template you meant when you put data on the context, we have a few options:\r\n\r\n>> * don't allow it. since object keys must be unique in javascript, and we cannot match up data correctly when two templates have the same name. This, of course, would mean that you can't do what you're doing.\r\n>> * use full file paths for all object keys and camelize the key so that in templates you would use variables like templates_pages_marketing_splash.title. I'm not a big fan of this option.\r\n>> * don't decide for the user and give them a renameKey option so they can have multiple templates with the same name.\r\n\r\nJust to make sure we're on the same page. My input data looks like this:\r\n```\r\nsource/data/2765/DE/83.json\r\nsource/data/5000/DE/83.json\r\n```\r\n\r\nAs it stands from my perspective I need the `data/2765/DE` and `data/5000/DE` parts to be part of my ID, otherwise I would just get `source/data/5000/DE/83.json` rendered to the output directory.\r\n\r\n>> We decided to go with 3, since our experience has been that only users who have advanced needs will even need to know that such an option exists.\r\n\r\nI didn't bother to think this was an advanced scenario. Before assemble I was using a Ruby generator called nanoc which also has the concept of \"item IDs\" which by default map to path names without extension, e.g. `source/data/2765/DE/83`. I think this would be a sane default as I found the culprit only after 3 hours of debugging.\r\n\r\n>> Although, I'm still a little confused on where you are with this, e.g. were you saying that you are now able to accomplish what you need with renameKey, or it's not working for you?\r\n\r\nThere are two spots where I need the modified ID:\r\n\r\n* The loader returns `acc[removeExtension(path.normalize(file))] = template;` (object key == `source/data/2765/DE/83`)\r\n* And I defined \r\n```js\r\n// Map e.g. dist/2765/DE/83/index.html back to the product template's ID.\r\nassemble.option('renameKey', function(fp) {\r\n  var res = path.join(path.dirname(fp), removeExtension(path.basename(fp)));\r\n  return path.relative(process.cwd(), res);\r\n});\r\n```\r\n\r\nHere are some questions for you:\r\n* How would a single `renameKey` option work with mixed content? Using default loaders, custom loaders and a few `assemble.page()` statements? IMHO the `renameKey` would need to handle all of them, unless you split them into separate `assemble.tasks`. Would that be the preferred option?\r\n* Related to #642, right now I just tried `.pipe(rename({}))` to compute the desired output file name. If I change the rename logic I would also need to change `renameKey` to get the correct template ID back. With my limited knowledge about assemble (please bear with me) this seems unfortunate as I need to define the mapping in two places.\r\n\r\nAgain, please bear with me if my questions appear stupid. Right now I just find it very hard to grok your mental models of how a static site should be built. I like to learn and get other people's concepts. It's just the limited documentation and missing samples that's making it a bit harder for me to stumble into that pit of success I was talking about. Thank you very much for your ongoing support!"},"comment":{"url":"https://api.github.com/repos/assemble/assemble/issues/comments/75573582","html_url":"https://github.com/assemble/assemble/issues/645#issuecomment-75573582","issue_url":"https://api.github.com/repos/assemble/assemble/issues/645","id":75573582,"user":{"login":"jonschlinkert","id":383994,"avatar_url":"https://avatars.githubusercontent.com/u/383994?v=3","gravatar_id":"","url":"https://api.github.com/users/jonschlinkert","html_url":"https://github.com/jonschlinkert","followers_url":"https://api.github.com/users/jonschlinkert/followers","following_url":"https://api.github.com/users/jonschlinkert/following{/other_user}","gists_url":"https://api.github.com/users/jonschlinkert/gists{/gist_id}","starred_url":"https://api.github.com/users/jonschlinkert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonschlinkert/subscriptions","organizations_url":"https://api.github.com/users/jonschlinkert/orgs","repos_url":"https://api.github.com/users/jonschlinkert/repos","events_url":"https://api.github.com/users/jonschlinkert/events{/privacy}","received_events_url":"https://api.github.com/users/jonschlinkert/received_events","type":"User","site_admin":false},"created_at":"2015-02-23T16:13:41Z","updated_at":"2015-02-23T16:13:41Z","body":"did any of the suggestions about renaming files on the other issue help with this?"}}