StenopePHP / Stenope

The static website generator for Symfony developers
https://stenopephp.github.io/Stenope/
MIT License
119 stars 9 forks source link

Include/Exclude pattern options #180

Open tacman opened 1 year ago

tacman commented 1 year ago

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 commented 1 year ago

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

tacman commented 1 year ago

Where in the code is that handled?

It looks like there are 2 passes for creating the static pages, the pages that don't take parameters, so you must inspect the available routes, and then crawling the site. Is that correct? 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.

On Tue, Nov 7, 2023 at 8:27 AM Maxime Steinhausser @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/StenopePHP/Stenope/issues/180#issuecomment-1798519426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEXIQILWQWKXL3GJAE2APTYDIZLVAVCNFSM6AAAAAA7BFHWKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJYGUYTSNBSGY . You are receiving this because you authored the thread.Message ID: @.***>

ogizanagi commented 1 year ago

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 https://github.com/StenopePHP/Stenope/issues/167 indeed

Where in the code is that handled?

There are two places indeed :

tacman commented 1 year ago

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 commented 1 year ago

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

tacman commented 1 year ago

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 commented 10 months ago

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.