2023-11-01 21:11:32 +02:00
# Static Generator
To generate the static content of the website, lucent provides a helper class.
## Laravel Command
2026-05-06 23:42:32 +03:00
Create an Artisan command and inject `StaticGenerator` :
2023-11-01 21:11:32 +02:00
``` php
2026-05-06 23:42:32 +03:00
class GenerateStatic extends Command
{
protected $signature = 'generate:static' ;
public function __construct (
public StaticGenerator $staticGenerator ,
public Context $ctx ,
) {
parent :: __construct ();
}
public function handle () : void
{
$this -> staticGenerator -> run ( 'generate:static' , function ( $writer ) {
$writer -> save ( " / " , $this -> ctx -> render ( " homepage " ));
$writer -> save ( " /about " , $this -> ctx -> render ( " about " ));
});
}
2023-11-01 21:11:32 +02:00
}
```
2026-05-06 23:42:32 +03:00
`run(string $signature, callable $callback)` — the first argument must match the command's artisan signature. This is used to stream live build logs in the Lucent UI. The callback receives a `Writer` instance.
2023-11-01 21:11:32 +02:00
2026-05-06 23:42:32 +03:00
## Writer: save
Writes an HTML file at the given path:
``` php
$writer -> save ( " /blog/my-post " , $html );
// writes to: storage/lucent/build/blog/my-post/index.html
```
An optional third argument changes the file extension (default `"html"` ).
## Writer: createRedirect
Generates an HTML meta-refresh redirect. Useful for root-level locale redirects:
2023-11-01 21:11:32 +02:00
``` php
2026-05-06 23:42:32 +03:00
$writer -> createRedirect ( " / " , " /el " );
$writer -> createRedirect ( " / " , " /el " , " Redirecting " , " Please wait... " );
2023-11-01 21:11:32 +02:00
```
2026-05-06 23:42:32 +03:00
Arguments: `from` , `to` , `title` (default `"Redirecting"` ), `message` (default `"Redirecting Soon..."` ).
2023-11-01 21:11:32 +02:00
2026-05-06 23:42:32 +03:00
## Writer: recordIterator
2023-11-01 21:11:32 +02:00
2026-05-06 23:42:32 +03:00
Iterates over all records in paginated batches — useful when there are too many records to load at once:
2023-11-01 21:11:32 +02:00
``` php
2026-05-06 23:42:32 +03:00
$writer -> recordIterator (
query : fn ( int $limit , int $skip ) => $query
-> filter ([ " schema " => " blogPosts " ])
-> onlyPublished ()
-> limit ( $limit )
-> skip ( $skip )
-> tree (),
parser : function ( $records ) use ( $writer ) {
foreach ( $records as $record ) {
$writer -> save (
" /blog/ " . $record -> data -> slug ,
$this -> ctx -> render ( " blogPost " , $record ),
);
}
},
);
2023-11-01 21:11:32 +02:00
```
2026-05-06 23:42:32 +03:00
Signature: `recordIterator(callable $query, callable $parser, int $skip = 0, int $limit = 100): int`
The `$query` callable receives `($limit, $skip)` and must return a collection. Iteration stops automatically when a batch returns zero records.
2023-11-01 21:11:32 +02:00
## Storage and Permissions
2026-05-06 23:42:32 +03:00
All generated HTML is written to `storage/lucent/build` during the run, then atomically swapped to `storage/lucent/live` on completion. Create the public symlink with:
2023-11-01 21:11:32 +02:00
``` bash
php artisan lucent:livelink
```
2026-05-06 23:42:32 +03:00
The static site is then accessible at `http://localhost:8000/live` . To serve it without the `/live` prefix, add this to your nginx vhost:
2023-11-01 21:11:32 +02:00
``` nginxconf
location / {
try_files /live$uri/index.html /live$uri $uri $uri/ /index.php?$query_string;
}
```
2026-05-06 23:42:32 +03:00
## Artisan Commands
| Command | Description |
|---|---|
| `lucent:setup-db` | Create all Lucent database tables |
| `lucent:schemas` | Compile schema JSON files |
| `lucent:livelink` | Create the `public/live` symlink |
| `lucent:rebuild:thumbnails` | Regenerate thumbnails for all uploaded images |
| `lucent:removeOrphanEdges` | Remove edges pointing to deleted records |
| `lucent:generate:collection {name}` | Scaffold a new collection schema JSON file |
2023-11-01 21:11:32 +02:00
## Build from the Lucent UI
2026-05-06 23:42:32 +03:00
Register your generate command in `config/lucent.php` so admin users can trigger it from the UI:
2023-11-01 21:11:32 +02:00
``` php
2026-05-06 23:42:32 +03:00
" commands " => [
" generate:static " => " Generate Static Site " ,
],
2023-11-01 21:11:32 +02:00
```
2026-05-06 23:42:32 +03:00
Only roles listed in `canBuild` can trigger commands from the UI.
2023-11-01 21:11:32 +02:00