More prety way to ignore Image and CSS on Join

Splash Forums Rewrite Users More prety way to ignore Image and CSS on Join

This topic contains 3 replies, has 2 voices, and was last updated by  salviof 2 years, 11 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #24783

    salviof
    Participant

    That is recomended in forum to ignore images on server :

    .addRule(Join.path(“/{page}”).to(“/{page}.jsf”) )
    .when(Not.any(Path.matches(“/image”)))
    .where(“page”).matches(“[a-zA-Z/]+”)

    but I have many joins how is the solution more pretty, with especific the execptions only one time?

    I need ignore all css and images in many diretory how about *.jpg like: Not.any(Path.matches(“*.jpg”).Not.any(Path.matches(“*.gif”)..Not.any(Path.matches(“*.css”)
    How the pretty way to do this?

    (Sorry bad inglsh)

    Thanks

    #24791

    I typically create a private method in the configuration provider like this:

    private Condition isNoStaticResource() {
      return Not.any( Path.matches("{*}.jpg").or( Path.matches("{*}.gif") ) );
    }
    

    Then I can use this method to add the condition to multiple rules like this:

    .addRule(Join.path(“/{page}”).to(“/{page}.jsf”) )
    .when(isNoStaticResource()))
    .where(“page”).matches(“[a-zA-Z/]+”)
    

    You could also create a custom condition which is very very simple. Something like this:

    public class NoStaticResource implements Condition {
    
      public boolean evaluate(Rewrite event, EvaluationContext context) {
    
        Condition wrapped = Not.any( Path.matches("{*}.jpg").or( Path.matches("{*}.gif") ) );
    
        return wrapped.evaluate(event, context);
    
      } 
    
    }
    

    Then you can use your custom condition like this:

    .addRule(Join.path(“/{page}”).to(“/{page}.jsf”) )
    .when( new NoStaticResource() )
    .where(“page”).matches(“[a-zA-Z/]+”)
    
    #24795

    salviof
    Participant

    Thanks bro!!!!

    #24796

    salviof
    Participant

    ok

    • This reply was modified 2 years, 11 months ago by  salviof.
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Comments are closed.