static export
Stancy integrates spatie/laravel-export to export your pages as static files.

Configuration

We recommend to disable the crawl option and export only listed paths/pages. The paths option can be empty if you only want to export feeds and/or pages. But you also can add additional paths, like the sitemap, to export.
config/export.php
1
<?php
2
​
3
return [
4
// to only export listed paths/pages
5
'crawl' => false,
6
​
7
'paths' => [
8
'/sitemap.xml',
9
],
10
];
Copied!

prepare Pages

By default you can't export any page, only the feeds. To allow page export you have to implement the \Astrotomic\Stancy\Contracts\Routable interface in your page data class. This interface is also good to add your pages to a sitemap and feeds.
app/Pages/Home.php
1
<?php
2
​
3
namespace App\Pages;
4
​
5
use Astrotomic\Stancy\Contracts\Routable;
6
use Astrotomic\Stancy\Models\PageData;
7
​
8
class Home extends PageData implements Routable
9
{
10
public function getUrl(): string
11
{
12
return url('/');
13
}
14
}
Copied!

ExportFactory

To add your pages programmatically you should use a service provider. This service provider should be the last or at least after \App\Providers\RouteServiceProvider in your app.providers configuration. In the service provider you should use the boot() method where you can inject the \Astrotomic\Stancy\Contracts\ExportFactory service and add a new booted event listener.
app/Providers/ExportServiceProvider.php
1
<?php
2
​
3
namespace App\Providers;
4
​
5
use Astrotomic\Stancy\Contracts\ExportFactory as ExportFactoryContract;
6
use Illuminate\Support\ServiceProvider;
7
​
8
class ExportServiceProvider extends ServiceProvider
9
{
10
public function boot(ExportFactoryContract $exportFactory)
11
{
12
$this->app->booted(function () use ($exportFactory) {
13
$exportFactory
14
->addFeeds()
15
->addSheetList(['static:home', 'static:blog'])
16
->addSheetCollectionName('blog')
17
;
18
});
19
}
20
}
Copied!
This service provider will add all feeds, blog posts and the home and blog static pages.
Last modified 2yr ago