Skip to content

Commit

Permalink
Merge pull request #34 from BobWez98/feature/sites
Browse files Browse the repository at this point in the history
Allow the creation of Sites with Builder
  • Loading branch information
tdwesten authored Oct 31, 2024
2 parents 9d02195 + b4b32af commit d1fc80e
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 11,650 deletions.
92 changes: 91 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Statamic Builder

The Statamic Builder speeds up building Statamic sites. It offers a clear method to define blueprints, fieldsets, collections, naviations and taxonomies using PHP classes. This approach enhances code readability and maintainability compared to writing YAML files.
The Statamic Builder speeds up building Statamic sites. It offers a clear method to define sites, blueprints, fieldsets, collections, naviations and taxonomies using PHP classes. This approach enhances code readability and maintainability compared to writing YAML files.

For example, you can define a collection blueprint as follows:

Expand Down Expand Up @@ -360,3 +360,93 @@ This addon enables you to define collections and taxonomies in PHP classes, simp
],
];
```

### How to create a Site

> [!WARNING]
The sites are cached forever. When adding a site, you need to clear the cache.

1. Create a new site by running the following command:

```bash
php artisan make:site Blog
```

2. Define your site in the generated file. For example:

```php
<?php

namespace App\Sites;

use Tdwesten\StatamicBuilder\BaseSite;

class Blog extends BaseSite
{
/**
* Return the handle for the site
*
* Example: return 'default';
*/
public function handle(): string
{
return 'blog';
}

/**
* Return the handle for the site
*
* Example: return 'Default';
*/
public function name(): string
{
return 'Blog';
}

/**
* Return the base url for the site
*
* Example: return '/';
*/
public function url(): string
{
return '/blog';
}

/**
* Return the locale of the site
*
* Example: return '/';
*/
public function locale(): string
{
return 'en_US';
}

/**
* Return the array of extra attributes for the site
*
* Example: return ['foo' => 'bar'];
*/
public function attributes(): array
{
return [];
}
}
```

3. Register the Site in your `config/statamic/builder.php` file:

```php
<?php
return [
'sites' => [
\App\Sites\Blog::class
],
];
```

4. Clear the cache:
```bash
php artisan cache:clear
```
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
"php": "^8.2",
"illuminate/support": "^10.0|^11.0",
"laravel/framework": "^10.0|^11.0",
"statamic/cms": "^4.46|^5.0"
"statamic/cms": "^5.0"
},
"require-dev": {
"pestphp/pest": "^2.33",
"laravel/pint": "^1.7",
"orchestra/testbench": "^8.0",
"spatie/laravel-ray": "^1.36",
"pestphp/pest-plugin-laravel": "^2.2",
"statamic/eloquent-driver": "^3.4"
"statamic/eloquent-driver": "^4.16"
},
"config": {
"allow-plugins": {
Expand Down
Loading

0 comments on commit d1fc80e

Please sign in to comment.