Closed jonschlinkert closed 10 years ago
@jonschlinkert What about grunt.file.expandMapping's rename
option?
@adjohnson916 that would work, is there an advantage in using that over just modifying page.dest
? Admittedly I didn't put that much thought into this yet.
It would be less powerful in the sense that it runs before assemble as thus wouldn't be aware of data or replacement tokens. But for the use case you listed, it could work, e.g.:
{
cwd: 'src/blog/'
, src: ['**/*.hbs']
, dest: 'dest/blog/'
, rename: function(dest, matchedSrcPath, options) {
return path.join(dest, matchedSrcPath.replace(/(\d+)-(\d+)-(\d+)/, function (a, y, m, d) {
return [y,m,d].join('/');
});
}
}
Ah, got it. I suggested something similar in the past as a quickfix for permalinks (more like "pretty links"), I think that's a great example that I should add to the docs if you don't mind, in case users want another way to modify paths.
I'm thinking that since our user base has a lot of both developers and designers it's generally good to have options for both. the non-devs might want an option to automatically look for dates in paths and parse them. For this to work without a lot of config I guess the date patterns would need to be restricted to a couple different structures, like yyyy-mm-dd
etc.
then we can do something like this:
pathArray.map(function(segment) { if(moment(segment).isValid()) { // do something }};
Again, I haven't spent too much time thinking this through, but that seems like a reasonable approach. Do you think this is unnecessary, should we just emphasize that a rename
function can be passed in?
closing. after further thought I think this just complicates things
One example is to parse a directory structure like this:
src/blog/2012-12-01/
and convert it to something like this:dest/blog/2012/12/01/