antlur/laravel-static-export

Export your laravel site as static files

v0.1.2 2024-02-24 17:45 UTC

This package is auto-updated.

Last update: 2024-10-24 19:10:40 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Host your Laravel site on Netlify, Vercel, or any other static site host. This package will generate static files from your Laravel site with very little setup. A convenient attribute is provided to provide routes with dynamic parameters.

Installation

You can install the package via composer:

composer require antlur/laravel-static-export

You can publish the config file with:

php artisan vendor:publish --tag="static-export-config"

This is the contents of the published config file:

return [
    'output_path' => base_path('dist'),

    'clear_before_export' => true,
];

Usage

php artisan export

Dynamic Data during static site generation

When generating the static site, you can use the ExportPaths attribute to define which routes should be generated. This is useful when you have dynamic data that you want to generate static pages for. For example, if you have a blog and you want to generate static pages for each blog post, you can use the ExportPaths attribute to define which routes should be generated. The rest of your logic can be handled as if it was a normal Laravel application.

// web.php
Route::get('/blog/{slug}', [BlogController::class, 'show']);

// app/Http/Controllers/BlogController.php
use Antlur\Export\Attributes\ExportPaths;

class BlogController
{
    // You can pass a class that implements PathProvider
    #[ExportPaths(BlogPostPaths::class)]
    public function show(string $name)
    {}

    // Or you can pass an array of paths directly
    #[ExportPaths(['/blog/first-post', '/blog/second-post'])]
    public function show(string $name)
    {}
}

// app/PathProviders/BlogPostPaths.php
class BlogPostPaths implements \Antlur\Export\Contracts\PathProvider
{
    public function paths(): array
    {
        return [
            '/blog/first-post',
            '/blog/second-post',
        ];
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.