2017 © Pedro Peláez
 

library mozhi

A Laravel Package

image

aheenam/mozhi

A Laravel Package

  • Wednesday, June 20, 2018
  • by rathesDot
  • Repository
  • 1 Watchers
  • 1 Stars
  • 57 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 5 Open issues
  • 9 Versions
  • 14 % Grown

The README.md

Do not use in production yet, (*1)

Mozhi

The package provides a simple way to add a static files based CMS to your Laravel project. It uses Markdown files as the content provider and uses Laravel's Blade for templating., (*2)

Requirements

This package requires PHP 7.2 and a Laravel version >= 5.7., (*3)

Installation

You can install the package via composer:, (*4)

composer require aheenam/mozhi

Configuration

Mozhi comes with a set of configuration possibilities, so make sure to check the config file's content:, (*5)

<?php

return [

    /**
     * The name of the disk Laravel's filesystem should use to search
     * for the content files. Mozhi expects a content directory inside of
     * the disk where the contents a located
     *
     * Default is set to local, that means storage_path('app/')
     * will be used to look for a contents directory
     */
    'content_disk' => env('MOZHI_CONTENT_DISK', 'local'),

    /**
     * the path where the themes are located, must be relative to the
     * base_path
     */
    'theme_path' => env('MOZHI_THEME_PATH', 'resources/themes/'),

    /**
     * The name of the theme that should be used to render the views
     */
    'theme' => env('MOZHI_THEME', 'default'),

    /**
     * The name of the template that should be used if no template was defined
     * in the page's markdown file
     */
    'default_template' => env('MOZHI_DEFAULT_TEMPLATE', 'page'),

    /**
     * Add all the CommonMark extension you want to use
     */
    'markdown_extensions' => [
        new \Webuni\CommonMark\TableExtension\TableExtension()
    ]

];

All the keys are commented well enough, so the usage should not be too tough. If there is something not that clear, feel free to post an issue., (*6)

As you see all the config variables can be set using the env file, but if you want, you can also publish them to change the values., (*7)

$ php artisan vendor:publish --provider="Aheenam\Mozhi\MozhiServiceProvider"

Usage

After the setup all of your routes will be caught by Mozhi and the package will try to find the appropriate content file for it., (*8)

Consider the config as above and then a call to /blog/awesome-blog. Now Mozhi will look for a file in storage/contents/blog/ that is named awesome-blog.md., (*9)

If it is found, it will render the specified template of the currenty theme and pass the content and the header of the markdown file., (*10)

The MarkDown files are parsed using Spatie's awesome package called YAML Front Matter before parsing the markdown, so you can (and should decorate) your markdown files., (*11)

So in your template file you can use the $content and the $meta variables. First is the html of the content file and $meta is an array of all header data specified in the Markdown file., (*12)

Note: If no template was specified it will fallback to the default_theme specified in the config., (*13)

Parsing Markdown

Mozhi uses the CommonMark implementation of The PHP League to parse Markdown to HTML. They offer a way to extend the specification. Mozhi uses the Table Extension by default, but you can manage all the extension by changing the markdown_extensions array in the config., (*14)

Changelog

Check CHANGELOG for the changelog, (*15)

Testing

To run tests use, (*16)

$ composer test

Contributing

Security

If you discover any security related issues, please email rathes@aheenam.com or use the issue tracker of GitHub., (*17)

About

Aheenam is a small company from NRW, Germany creating custom digital solutions. Visit our website to find out more about us., (*18)

License

The MIT License (MIT). Please see License File for more information., (*19)

The Versions