Skip to content

Mix markdown, frontmatter and eloquent models to easily handle markdown files with meta information by treating them as objects.

Notifications You must be signed in to change notification settings

hyn/eloquent-markdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eloquent markdown

GitHub license Latest Stable Version Build Status Total Downloads Donate

Ever felt like your markdown files could use meta information.. And once you've added frontmatter logic, whether it would be amazing to handle those files more humanely..

So let's combine markdown files, frontmatter and eloquent!

That something like the below:

{
  "title": "Some elaborate .."
}
And of course your regular markdown nonsense.

Mutates into an object:

echo $page->title; // Some elaborate ..
echo $page->getRenderedMarkdown(); // <p>And of course your regular markdown nonsense.</p>
echo $page->getMarkdown(); // And of course your regular markdown nonsense.
$page->setMarkdown('Foojaa'); // Yes update
$page->markdown = 'Foobar'; // Or on the assigned property
$page->save(); // Write the file to disk, YES!

Installation

composer require hyn/eloquent-markdown

Now create a model you want to use for markdown files:

class Page extends \Hyn\Eloquent\Markdown\Model
{}

And setup the filesystem and markdown parser resolution, add in AppServiceProvider or somewhere:

use Hyn\Eloquent\Markdown\Model;
use Hyn\Frontmatter\Parser;
use cebe\markdown\Markdown;

// ..

public function register() {
            Model::setMarkdownParser(new Parser(new Markdown));
            Model::setFilesystem($this->app->make('filesystem')->disk('content'));
}

Set content to the disk you configured to load the markdown files from. Or instantiate your own filesystem instance.

Usage

So if you have a file some/foo.md, use Page::find('some/foo.md'); to create a Page object, where any frontmatter meta information is stored as properties, the markdown contents are stored in the original state as the markdown property and the generated html is assigned to the contents attribute.

Other stuff that works:

  • save()
  • delete()
  • update the markdown property to renew the rendered content property automatically

About

Mix markdown, frontmatter and eloquent models to easily handle markdown files with meta information by treating them as objects.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages