-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81b1f79
commit 024f5fd
Showing
1 changed file
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,87 @@ By parsing Frontmatter into **Eloquent models**, Fusion empowers developers to b | |
|
||
You can install the package via composer: | ||
|
||
```bash | ||
```shell | ||
composer require hi-folks/fusion | ||
``` | ||
|
||
## Usage | ||
|
||
Once you installed Fusion you can start the process of creating content in Markdown files and querying the files through the Models. | ||
For example, now we are going to create articles in Markdown format and we will parse and query them like you can do it with a database. | ||
|
||
### Creating the content | ||
In the `resources/content` directory, you can create the `article` directory. | ||
In the `resources/content/article`, you can create your Markdown files with a frontmatter header like for example: | ||
|
||
```markdown | ||
--- | ||
date: 2024-04-05 | ||
title: Example title for article 1 | ||
excerpt: This will be a short excerpt from article number 1. | ||
published: true | ||
--- | ||
|
||
# Article 1 | ||
|
||
Markdown goes here | ||
``` | ||
|
||
you can name this file as `resources/content/article/article-1.md` | ||
You can create similarly the other Markdown files. These files represent your articles. | ||
|
||
### Creating the Model | ||
Similarly, you are doing with a database, you can create your model for loading the markdown files. | ||
Because you are creating articles you can create your model as `app/Models/Article.php`. | ||
|
||
You can fill the file in this way: | ||
|
||
```php | ||
// Usage description here | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
|
||
use HiFolks\Fusion\Models\FusionBaseModel; | ||
use Sushi\Sushi; | ||
|
||
class Article extends FusionBaseModel | ||
{ | ||
use Sushi; | ||
|
||
public function getRows() | ||
{ | ||
return parent::getRows(); | ||
|
||
} | ||
|
||
public function frontmatterFields(): array | ||
{ | ||
return [ | ||
"excerpt" | ||
]; | ||
} | ||
|
||
} | ||
|
||
``` | ||
Consider that: | ||
- the class has to extend the FusionBaseModel with `extends FusionBaseModel`; | ||
- you have to use the trait Sushi: `use Sushi;` | ||
- you have to implement the `getRows()` function returning `return parent::getRows();` | ||
- you have to implement the `frontmatterFields()` function for returning the list of the field names used in the frontmatter header. | ||
|
||
### Querying the content | ||
Now in your Controllers or your Blade components, you can use the `Article` model with the usual method like `where()`, `orderBy()` etc: | ||
|
||
```php | ||
$articles = \App\Models\Article | ||
::where('published', true) | ||
->orderBy('date') | ||
->get(); | ||
``` | ||
|
||
|
||
|
||
### Testing | ||
|
||
|
@@ -29,19 +101,19 @@ composer test | |
|
||
### Changelog | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. | ||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details. | ||
|
||
### Security | ||
|
||
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
If you discover any security-related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## Credits | ||
|
||
- [Roberto B](https://github.com/hi-folks) | ||
- [Roberto B](https://github.com/roberto-butti) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|