Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

middleware #50

Closed
jonschlinkert opened this issue Mar 27, 2014 · 5 comments
Closed

middleware #50

jonschlinkert opened this issue Mar 27, 2014 · 5 comments
Labels
Milestone

Comments

@jonschlinkert
Copy link
Member

@doowb, I'd like to add a middleware option that essentially takes an array of middlewares. Each middleware would just be replacement patterns. So instead of this:

options: {
  permalinks: {
    structure: ':year/:month/:day/:post/index.html',
    patterns: [
      {
        pattern: ':year',
        replacement: function(str) {
          var path = require('path');
          var name = path.basename(str, path.extname(str));
          var re = /(\d{4})-(\d{2})-(\d{2})-(.+)/;
          return name.replace(re, '$');
        }
      },
      {
        pattern: ':month',
        replacement: function(str) {
          var path = require('path');
          var name = path.basename(str, path.extname(str));
          var re = /(\d{4})-(\d{2})-(\d{2})-(.+)/;
          return name.replace(re, '$2');
        }
      },
      {
        pattern: ':day',
        replacement: function(str) {
          var path = require('path');
          var name = path.basename(str, path.extname(str));
          var re = /(\d{4})-(\d{2})-(\d{2})-(.+)/;
          return name.replace(re, '$3');
        }
      },
      {
        pattern: ':post',
        replacement: function(str) {
          var path = require('path');
          var name = path.basename(str, path.extname(str));
          var re = /(\d{4})-(\d{2})-(\d{2})-(.+)/;
          return name.replace(re, '$4');
        }
      }
    ]
  }
}

you could do this:

options: {
  permalinks: {
    structure: ':year/:month/:day/:post/index.html',
    middleware: [require('posts')]
  }
}

Or ideally middlewares would be able to define all options, so if you can use the middleware's defaults, you could just do:

options: {
  permalinks: {
    middleware: [require('posts')]
  }
}

But the latter isn't a have-to-have. I'm not as familiar with the Strings lib as I'd like to be, so I'm not sure what needs to be done to implement this. @doowb can you take a crack at it?

@jonschlinkert jonschlinkert added this to the v0.4.0 milestone Mar 27, 2014
@jonschlinkert
Copy link
Member Author

In the latter, it seems we would just be extending the options with each middleware, similar to how .assemblerc.yml works. so I expect they would have to be called in the order specified in the array.

@hariadi
Copy link
Member

hariadi commented Mar 28, 2014

👍

@doowb
Copy link
Member

doowb commented Mar 28, 2014

This should be simple enough to do the first one. I'm not sure if we could do the first and second unless I'm assuming each middleware object will always look like the options:

middleware: [
  {
    structure: ':year/:month/:day/:post/index.html',
    permalinks: {
      ...
    }
  }
]

@jonschlinkert
Copy link
Member Author

I think we need to have a spec for getting/setting values with the context. if we spend some time explaining how/when certain values can be set during the build, then at least the logic and conventions for this kind of thing will be easier to standardize and generalize. (for anyone reading, this won't be easy.)

@jonschlinkert
Copy link
Member Author

this is possible with the 0.6 release of assemble

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants