assemble / grunt-assemble-permalinks

Permalinks middleware for Assemble, the static site generator for Grunt.js and Yeoman. This plugin enables powerful and configurable URI replacement patterns, presets, uses Moment.js for parsing dates, and much more.
MIT License
43 stars 11 forks source link

add replacement option to use paths for replacement patterns #22

Closed jonschlinkert closed 10 years ago

jonschlinkert commented 10 years ago

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/

AndersDJohnson commented 10 years ago

@jonschlinkert What about grunt.file.expandMapping's rename option?

jonschlinkert commented 10 years ago

@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.

AndersDJohnson commented 10 years ago

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('/');
    });
  }
}
jonschlinkert commented 10 years ago

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:

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?

jonschlinkert commented 10 years ago

closing. after further thought I think this just complicates things