roelofjan-elsinga / flat-file-cms
A drop-in flat file CMS for Laravel.
Fund package maintenance!
roelofjan-elsinga
Patreon
Installs: 285
Dependents: 0
Suggesters: 0
Security: 0
Stars: 184
Watchers: 5
Forks: 19
Open Issues: 3
Requires
- php: ^8.1|^8.2
- ext-dom: *
- illuminate/console: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- roelofjan-elsinga/content-to-html-parser: ^0.5
- roelofjan-elsinga/sitemap-generator: ^0.6
- spatie/yaml-front-matter: ^2.0
- symfony/yaml: ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- mikey179/vfsstream: ^1.6
- orchestra/testbench: ^7.4
- pestphp/pest: ^1.22
- dev-master
- 4.4.1
- 4.4.0
- 4.3.0
- 4.2.3
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.2
- 4.0.1
- 4.0.0
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 2.0.0
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- 1.0.0-alpha.2
- 1.0.0-alpha.1
- 0.16.2
- 0.16.1
- 0.16.0
- 0.15.0
- 0.14.0
- 0.13.1
- 0.13.0
- 0.12.1
- 0.12.0
- 0.11.1
- 0.11.0
- 0.10.7
- 0.10.6
- 0.10.5
- 0.10.4
- 0.10.3
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.1
- 0.8.0
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1
- dev-dependabot/composer/guzzlehttp/psr7-2.5.0
- dev-dependabot/composer/symfony/http-kernel-6.2.6
- dev-psalm-integration
This package is auto-updated.
Last update: 2024-11-14 12:28:39 UTC
README
This package contains a drop-in CMS that uses files to store its contents.
For the full documentation, go to the Aloia CMS Documentation website.
Installation
You can include this package through Composer using:
composer require roelofjan-elsinga/aloia-cms
and if you want to customize the folder structure, then publish the configuration through:
php artisan vendor:publish --provider="AloiaCms\\AloiaCmsServiceProvider"
Creating a custom content type
Creating a custom content type is very simple. All you have to do is create a class that extends AloiaCms\Models\Model
,
specify a $folder_path
, and optionally add required fields to $required_fields
. An example can be found below:
namespace App\Models; use AloiaCms\Models\Model; class PortfolioItem extends Model { protected $folder = 'portfolio_items'; protected $required_fields = [ 'name', 'github_url', 'description', ]; }
Once you have a class like this, you can interact with it like described under "Usage of models"
Built-in models
There are 4 built-in models which you can use without any additional set-up:
- Page
- Article
- ContentBlock
- MetaTag
Of course, you can add your own models as described at "Creating a custom content type".
Usage of models
In this example we're looking at one of the built-in content types: Article. You can use these same steps for all classes that extend from "AloiaCms\Models\Model".
To load all articles in the "articles" folder in the folder you specified in
config('aloiacms.collection_path')
you can use the following script:
use AloiaCms\Models\Article; /**@var Article[]*/ $articles = Article::all();
You can use that to display your posts on a page. You can also load a single post, using:
$post_slug = 'this-post-is-amazing'; $article = Article::find($post_slug);
If you only want all published posts, you'll need to retrieve them like so:
$published_articles = Article::published();
To get the raw contents of each article (content + front matter), you can use:
$post_slug = 'this-post-is-amazing'; $articles = Article::find($post_slug)->rawContent();
And finally, to update your article, you can run:
use Carbon\Carbon; $post_slug = 'this-post-is-amazing'; Article::find($post_slug) ->setExtension('md') // md is the default, but you can use html as well. ->setMatter([ 'description' => 'This post is about beautiful things', 'is_published' => true, 'is_scheduled' => false, // Either use post_date in setMatter() or setPostDate() 'post_date' => date('Y-m-d') ]) ->setPostDate(Carbon::now()) ->setBody('# This is the content of an article') ->save();
Content blocks
You can manage small content blocks for your website through this package.
The content of the blocks are stored in a folder called "content_blocks"
inside of the config('aloiacms.collections_path')
folder.
You'll need to register the facade into your application, by placing the following
line to your aliases in config/app.php
:
'Block' => \AloiaCms\Facades\BlockFacade::class,
Now you can use the facade in your blade views by using:
{!! Block::get('content-file-name') !!}
This facade will look for a file in the folder you specified in
config('aloiacms.collections_path')
.
The Facade will parse the contents of the file to HTML to be able to render it.
If no file could be found, an empty string will be returned.
NOTE: You should not specify the extension of the filename you're passing to Block::get()
.
This will be parsed automatically.
Testing
You can run the included tests by running ./vendor/bin/phpunit
in your terminal.
Contributing
If you'd like to contribute to the CMS directly, you can create PR's on this repository. If you'd like to contribute to the documentation, you can create PR's on the repository for the documentation.