Static generation
With everything we have in place, it would be pretty trivial to add static site generation on top of existing controller methods.
Let's say we have a normal controller like this one:
class BlogPostController
{
#[Get('/')]
public function index(BlogPostRepository $repository): View
{
$blogPosts = $repository->all();
return view('overview.view.php', blogPosts: $blogPosts);
}
#[Get('/{blogPost}')]
public function show(BlogPost $blogPost): View
{
return view('show.view.php', blogPost: $blogPost);
}
}
We could create static generated pages from it like so:
class BlogPostController
{
#[Get('/')]
#[StaticPage]
public function index(BlogPostRepository $repository): View
{
$blogPosts = $repository->all();
return view('overview.view.php', blogPosts: $blogPosts);
}
#[Get('/{blogPost}')]
#[StaticPage]
public function show(
#[StaticVariable(BlogPostRepository::class)] BlogPost $blogPost
): View {
return view('show.view.php', blogPost: $blogPost);
}
}
Of course, naming tbd
Is the idea that the show() route will generate all the /{blogPost} static pages for all BlogPost items?
Yes, but this is a very low-priority issue. I just made a note because I wanna look into it somewhere in the future
I've added a #[StaticPage] attribute, as well as the DataProvider interface, as well as the static:generate and static:clean commands. I'll still need to write tests
TODO:
- [x] write test
- [x] write docs