statamic / ssg

The official Statamic Static Site Generator
234 stars 24 forks source link

Add a before hook #42

Closed tao closed 3 years ago

tao commented 3 years ago

I'm working on a Static Pagination solution, but it requires generating many new urls for each page. I need to create these dynamically based on the number of entries, pagination size, etc.

To generate the URLs I need to use some facades like Entry and Term, however you can't use these directly in the config files. This pull request allows you to hook into the generator before the config files are loaded, which allows you to modify the config and dynamically add new urls.

Hopefully it will also be useful for other purposes.

tao commented 3 years ago

Should be able to close issue #19 with this too.

jasonvarga commented 3 years ago

Thanks for the PR but I wasn't a fan of introducing a generic callback which is probably always going to be used to add urls. I just made a method to explicitly add the urls in #49

brighttank commented 3 years ago

A before hook would be useful to set env variables, clear caches, generate responsive images, etc.