tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

Static generation

Open brendt opened this issue 1 year ago • 2 comments

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

brendt avatar Apr 12 '24 08:04 brendt

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

chvanam avatar Jun 18 '24 21:06 chvanam

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

brendt avatar Jun 19 '24 11:06 brendt

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

brendt avatar Aug 29 '24 12:08 brendt

TODO:

  • [x] write test
  • [x] write docs

brendt avatar Aug 29 '24 13:08 brendt