Download the PHP package hi-folks/fusion without Composer
On this page you can find all versions of the php package hi-folks/fusion. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hi-folks/fusion
More information about hi-folks/fusion
Files in hi-folks/fusion
Package fusion
Short Description Laravel package that enhances Eloquent models to facilitate the management of structured, database-free content through Markdown files with Frontmatter.
License MIT
Homepage https://github.com/hi-folks/fusion
Informations about the package fusion
Fusion
Fusion is a Laravel package designed to manage Markdown content via Eloquent Models, eliminating the necessity for a conventional database setup. It achieves this by leveraging Markdown files enhanced with Frontmatter.
Fusion aids in website development by integrating the power of Markdown and Frontmatter, enabling developers to create content-driven Web sites without having to manage databases.
With Fusion, developers can leverage the simplicity of Markdown syntax combined with the flexibility of Frontmatter to seamlessly organize and structure content.
By parsing Frontmatter into Eloquent models, Fusion enables developers to create complex, structured websites with ease. Say goodbye to the complexities of database management and welcome simplified website development with Fusion.
[!WARNING] The package is under development (version 0.0.x), so the functions, classes and methods provided can be changed, especially for the
FusionBaseModel
model class. So, if you want to start using the package in order to provide feedback, you are welcome, but please don't use it in production until the version 1.0.0 will be released. Thank you
Installation
You can install the package via the composer
tool:
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:
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:
Consider that:
- the class has to extend the FusionBaseModel with
extends FusionBaseModel
; - you have to use the trait FusionModelTrait:
use FusionModelTrait;
- you have to implement the
frontmatterFields()
function for returning the list of the field names used in the frontmatter header.
Creating automatically the Model
If you want to create automatically the Model file, based on the structure and the content of the Markdown files you can use the fusion:sync-model
command:
The path
parameter sets the directory of the markdown files for a specific model (like article, page, post, project etc.).
The --create-model
option will generate automatically the Model file based on the content and the frontmatter section of the Markdown files.
Without the --create-model
option the fusion:sync-model
command will list some information detected from Markdown like the name of the Model and the list of the fields.
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:
Advanced Usage
Once you understand the basics of using Fusion with your Markdown files, you can use some of the advanced features. Consider that Fusion is a LAravel Package and during the design and the implementation of the Package we try to use and adhere to as much as possible the Laravel functionalities. With this approach, we think that we can inherit all the benefits of some Laravel features. Some of these feature that we explore and explain in the next sections are:
- Reloading the page of the website you are visualizing in the Browser when you change the Markdown content;
- Casting date in the Model so you can use the date in the Frontmatter headers;
- Casting collection in the Model so you can use complex and nested Frontmatter headers;
- Using the Check Markdown command for detecting the Frontmatter fields in the Markdown files.
Adding real-time page reload
If you want the browser to automatically reload the pages when you change some content in the Markdown files you can set the refresh
option in the laravel
Vite plugin.
In the vite.config.js
file add the refresh
option with the list of the folder you want that Vite will "watch" for changes and reload the page.
In the example, the resources/content
directory is added.
If you need to setup the Vite asset bundling you can take a look at the LAravel documentation: https://laravel.com/docs/11.x/vite
Using dates in the Markdown files
If you want to use date (or date-time) in your front matter you can use the format YYYY-MM-DD in the Frontmatter for example:
Then in the Model you can set the casting in this way:
Where date
is the field name, the same name you are using in the Markdown.
If you are adding a new field, remember to add the field name in the list of the frontmatter field in the frontmatterFields()
function in the Model:
If you are interested into exploring more the attribute casting in the Laravel Model you can take a look at The Laravel Eloquent attribute casting documentation.
Using collections in the Markdown files
If you need to manage complex data in the Markdown, like for example a list of tags you can use the arrays in the Frontmatter:
In the example, we are adding a field named head
which is an array of values for tag and content.
In the Model file, you have to cast properly the head
field as collection
.
So that in your blade files, you can loop through the head
field and access to tag
or content
sub-fields:
Customizing the slug
By default, the slug of a content is the filename without the extension.
Now you can customize the slug using the frontmatter attribute slug
.
For example:
Using the Check Markdown command
To inspect the Markdown files and show and list the Frontmatter fields you can use the Artisan command fusion:check
.
Using the Check Model command
To inspect the Model file and check if it extends the right class and uses the proper Traits to be a Model compatible with Markdown files, you can use the fusion:check-model
command:
The output will tell you if your model is correct or not:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please open an issue in the tracker using the "New issue" functionality.
Credits
- Roberto B
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
References
We built this Open Source project using some nice and powerful Open Source libraries like:
- Sushi: Eloquent's missing "array" driver;
- league/commonmark: Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs;
- yaml-front-matter: A to the point yaml front matter parser;
- PestPHP: Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP. Under the hood PestPHP uses PHPUnit, the PHP testing framework;
- RectorPHP: Instant Upgrades and Automated Refactoring of any PHP 5.3+ code;
- Laravel Pint: an opinionated PHP code style fixer for minimalists. Under the hood, Laravel Pint uses PHP-CS-Fixer the open source tool to automatically fix PHP Coding Standards issues.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of fusion with dependencies
calebporzio/sushi Version ^2.5
illuminate/support Version ^11.0
league/commonmark Version ^2.4
spatie/commonmark-highlighter Version ^3.0
spatie/yaml-front-matter Version ^2.0