tempestphp / tempest-framework

The PHP framework that gets out of your way 🌊
https://tempest.stitcher.io/framework/01-getting-started
MIT License
501 stars 34 forks source link

Static generation #234

Open brendt opened 2 months ago

brendt commented 2 months ago

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

chvanam commented 2 weeks ago

Is the idea that the show() route will generate all the /{blogPost} static pages for all BlogPost items?

brendt commented 2 weeks ago

Yes, but this is a very low-priority issue. I just made a note because I wanna look into it somewhere in the future