1.7 KiB
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.
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:
$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.
$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:
php artisan lucent:livelink
Now your static website is accessible at 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
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:
"generateCommand" => "generate:static"
That way, the users will be able to initiate the build command through the user interface.