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

Include/Exclude pattern options #180

Open
tacman opened this issue Nov 7, 2023 · 7 comments
Open

Include/Exclude pattern options #180

tacman opened this issue Nov 7, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@tacman
Copy link

tacman commented Nov 7, 2023

I trying to generate static pages for just part of a website. I know I can set stenope.ignore option to true in the #[Route()], but what I'd rather do is include or exclude route patterns.

For example, I never want a route that ends with _delete or _edit, as generated by the Symfony make:crud command.

And if I'm only exposing one entity, I might want to just include it, e.g. store_listing and store_show, without going into the controller and making the modifications there.

Is there a way to do that? something like

bin/console -e prod stenope:build ../static-stores --include=(app_homepage|store_*) exclude=*_(edit|delete) 

And/or something in the config/packages/stenope.yaml

@ogizanagi
Copy link
Member

For now, no such system exist for doing that in Stenope, yet.

@ogizanagi ogizanagi added the enhancement New feature or request label Nov 7, 2023
@tacman
Copy link
Author

tacman commented Nov 7, 2023 via email

@ogizanagi
Copy link
Member

I won't if there's a way to
disable the available routes and simply give a starting page, and crawl the
site from there.

This is the feature I described in #167 indeed

Where in the code is that handled?

There are two places indeed :

  • the GET routes without parameters, in the Builder :
    if ($route->isIgnored() || !$route->isGettable()) {
  • when generating an URL for a route during the building of another page, in the UrlGenerator :
    if (($routeInfo = $this->routesInfo[$name] ?? null) && !$routeInfo->isIgnored()) {

@tacman
Copy link
Author

tacman commented Nov 7, 2023

So it doesn't seem too complicated to add in an additional check. In fact, something like if ($this->isIncluded($route)) or isCandidate()... might be a place to consolidate include/exclude/ignored and gettable.

Adding a variable to the configuration isn't too hard, nor to the CLI. I'm a fan of the Symfony 6.1+ bundles, so easy to set up, but since there are no new services this should be fairly straightforward.

It's probably something I could do if you're in agreement. We probably need to flesh out a bit more what the patterns look like, regex with the delimiters?

@tacman
Copy link
Author

tacman commented Nov 7, 2023

Are there already globally ignored routes? Sometimes I want to test with dev, but obviously not the debug toolbar.

@tacman
Copy link
Author

tacman commented Nov 7, 2023

Alternatively, the routes could be filtered when they're being loaded, or set to ignored based on the pattern. Right now ignored is set to the Symfony $route $options property, but could also a property of $routeInfo. Anyway, definitely something you have a much better vision for, so I won't muck around with it yet.

@tacman
Copy link
Author

tacman commented Dec 27, 2023

Brainstorming: what about an option on the #[Route] attribute, or a dedicated attribute

#[StaticRoute(path: "/home")
#[Route(name: 'app_homepage', options=['static' => true])]

The CLI could optionally only generate routes tagged like this.

In particular, I'm thinking of how to generate the html pages for a PWA, where I only have a few pages that need to be generated in HTML, then rest will be either partial pages fetched (and cached) from a server, or simply JSON data (again, fetched and cached from the server). So I want to use Stenope for generating just the pages that will be part of the PWA manifest and 100% static.

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

No branches or pull requests

2 participants