# Static Generator

To generate the static content of the website, lucent provides a helper class.


## Laravel Command

Just create a command and name it as you like. Make sure to inject the StaticGenerator class.

```php
public function __construct(
    public StaticGenerator $staticGenerator,
) {
    parent::__construct();
}
```

## Redirect command

There are cases which is useful to create a redirect like when you have a multilingual website:

```php
$this->staticGenerator->run(function ($writer) {
    $writer->createRedirect("/", "/el");
});
```

## The Writer save command

In order to create an html file, you have to use the writer's save command

The first argument is the url and the second is the rendered HTML. That's where the page classes do come handy.

```php
$this->staticGenerator->run(function ($writer) {
    $writer->save("/", $this->ctx->render("homepage"));
    $writer->save("/about", $this->ctx->render("about"));
});
```

## Storage and Permissions

All the generated html is stored on `storage/lucent/live`
In order to make it accessible you have to create symlink:

```bash
php artisan lucent:livelink
```

Now your static website is accessible in http://localhost:8000/live

But it would not be nice to have the **live** prefix everywhere. That's why you need to make the following tweak in the nginx vhost

```nginxconf
location / {
    try_files /live$uri/index.html /live$uri $uri $uri/ /index.php?$query_string;
}
```

## Build from the Lucent UI

In your lucent.php config file you can define your command that is used to generate the static files:

```php
"generateCommand" => "generate:static"
```
That way, the users will be able to initiate the build command through the user interface.







