Giter Site home page Giter Site logo

Comments (7)

chrisguttandin avatar chrisguttandin commented on May 21, 2024 1

Hi @cschwaderer,

thanks for filing this issue? Unfortunately the --parameter-values argument is not really usable for your use case. It currently renders each route with all possible permutations. And as you discovered the parameter values can't be scoped to a specific route.

I like the schema that you proposed. Building up on this I would propose the following.

  • The current functionality keeps the same if you specify the JSON as this it will render 9 routes:
{
    ":id": ["1","2","3"],
    ":title": ["foo1","foo2","foo3"]
}
  • Additionally it should be possible to group parameters. This will only render 3 routes:
[
    {":id":["1"], ":title":["foo1"]},
    {":id":["2"], ":title":["foo2"]},
    {":id":["3"], ":title":["foo3"]}
]
  • And finally as you proposed it should be possible to scope parameters by routes:
{
    "/route-i-want-to-prerender/:id/:title": [
        { ":id": "1", ":title": "foo1" },
        { ":id": "2", ":title": "foo2" },
        { ":id": "3", ":title": "foo3" }
    ],
    "/another-route-i-want-to-prerender/:id/:title": [
        { ":id": "4", ":title": "bar4" },
        { ":id": "5", ":title": "bar5" },
        { ":id": "6", ":title": "bar6" }
    ],
}

This means a property of the JSON object can be either a parameter (":id") or a route ("/x/y/z"). If it starts with colon it's considered to be a parameter and if it starts with a slash it's considered to be a path.

The values must be either a string or an array of strings.

Does that sound reasonable to you?

from angular-prerender.

cschwaderer avatar cschwaderer commented on May 21, 2024

@chrisguttandin Thanks for reacting so fast! Yes, that sounds very reasonable to me in general.

Just one question for your second case:

[
    {":id":["1"], ":title":["foo1"]},
    {":id":["2"], ":title":["foo2"]},
    {":id":["3"], ":title":["foo3"]}
]

Why do the values need to be an array here? Wouldn't flat values like

[
    {":id":"1", ":title":"foo1"},
    {":id":"2", ":title":"foo2"},
    {":id":"3", ":title":"foo3"}
]

be better and clearer in this case?

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 21, 2024

Oh, sorry for not pointing that out. I think both should work. I'm trying to get the update done by the end of the week.

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 21, 2024

Hi @cschwaderer, v5.3 should support your use case now. Please let me know if you run into any issues.

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 21, 2024

I also updated the readme. Could you please have a look and tell me if you think it sufficiently explains how --parameter-values work.

from angular-prerender.

cschwaderer avatar cschwaderer commented on May 21, 2024

Thank you so much for implementing this to fast! Really helps me!

Now, first of all, just one question.
Instead of (as stated above)

{
    "/route-i-want-to-prerender/:id/:title": [
        { ":id": "1", ":title": "foo1" },
        { ":id": "2", ":title": "foo2" },
        { ":id": "3", ":title": "foo3" }
    ],
    "/another-route-i-want-to-prerender/:id/:title": [
        { ":id": "4", ":title": "bar4" },
        { ":id": "5", ":title": "bar5" },
        { ":id": "6", ":title": "bar6" }
    ],
}

the expected input is now

[
  { "/route-i-want-to-prerender/:id/:title": { ":id": "1", ":title": "foo1" }},
  { "/route-i-want-to-prerender/:id/:title": { ":id": "2", ":title": "foo2" }},
  { "/route-i-want-to-prerender/:id/:title": { ":id": "3", ":title": "foo3" }},
  { "/another-route-i-want-to-prerender/:id/:title": { ":id": "4", ":title": "bar4" }},
  { "/another-route-i-want-to-prerender/:id/:title": { ":id": "5", ":title": "bar5" }},
  { "/another-route-i-want-to-prerender/:id/:title": { ":id": "6", ":title": "bar6" }}
]

Is that on purpose for internal reasons? Because for the user, it's a little bit more verbose this way.

Additionally, since you asked me if the readme is clear enough, I'd say your example for this case is a somehow incomplete.
First of all, it's confusing because the routes used as an example do not contain params. Also, using at least two values per route would make clearer how it should look like.
My suggestion would be:

[{"/shirts/:id":{":id":"shirt-a"},{"/shirts/:id":{":id":"shirt-b"},"/shoes/:id":{":id":"shoe-a"}},"/shoes/:id":{":id":"shoe-b"}}]

As a last point: When passing wrong formatted values for --parameter-values, angular-prerenderer doesn't tell exactly what is wrong right now. You might want to think about including some kind of JSON schema check (I personally use https://github.com/tdegrunt/jsonschema for such cases) in order to provide more detailed errors.

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 21, 2024

I'm glad it helps you.

Both of your examples should work. You could even get rid of a couple of more characters:

{
    "/route-i-want-to-prerender": [
        { ":id": "1", ":title": "foo1" },
        { ":id": "2", ":title": "foo2" },
        { ":id": "3", ":title": "foo3" }
    ],
    "/another-route-i-want-to-prerender": [
        { ":id": "4", ":title": "bar4" },
        { ":id": "5", ":title": "bar5" },
        { ":id": "6", ":title": "bar6" }
    ]
}

It's only necessary to specify the portion of the route which is different from the others. I also allowed another schema to avoid the additional array in case there is only one set of parameter values per route. In that case you could use something like this...

{
    "/route-i-want-to-prerender": { ":id": "1", ":title": "foo1" },
    "/another-route-i-want-to-prerender": { ":id": "4", ":title": "bar4" }
}

Please let me know if that doesn't work. In that case I introduced a bug.

Adding a JSON schema validation is an excellent idea. I'll put it on the todo list.

I thought it makes the README simpler when I only use one parameter but I can see why that wasn't a good idea. Thanks for your feedback.

from angular-prerender.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.