aheenam/mozhi

Laravel 包

0.5.0 2019-02-28 19:49 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:01 UTC


README

尚未在生产环境中使用

Mozhi

该包提供了一种简单的方法将基于静态文件的CMS添加到您的Laravel项目中。它使用Markdown文件作为内容提供者,并使用Laravel的Blade进行模板渲染。

要求

此包需要 PHP 7.2 和 Laravel 版本 >= 5.7

安装

您可以通过composer安装此包

composer require aheenam/mozhi

配置

Mozhi附带了一套配置选项,请确保检查配置文件的内容

<?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()
    ]

];

所有键都进行了充分的注释,因此使用不应过于困难。如果有不清楚的地方,请随时发布问题。

如您所见,所有配置变量都可以使用env文件进行设置,但如果您愿意,也可以将其发布以更改值。

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

使用

设置完成后,所有路由都将由Mozhi捕获,并且包将尝试找到适当的内容文件。

考虑上述配置,然后调用 /blog/awesome-blog。现在Mozhi将在storage/contents/blog/中查找名为awesome-blog.md的文件。

如果找到,它将渲染当前主题指定的模板,并将Markdown文件的内容和标题传递给它。

Markdown文件在解析Markdown之前使用Spatie的出色包YAML Front Matter进行解析,因此您可以(并且应该)装饰Markdown文件。

因此,在模板文件中,您可以使用$content$meta变量。第一个是内容文件的HTML,而$meta是Markdown文件中指定的一组标题数据的数组。

注意:如果没有指定模板,则将回退到配置中指定的default_theme

解析Markdown

Mozhi使用The PHP League的CommonMark实现将Markdown解析为HTML。他们提供了一种扩展规范的方法。Mozhi默认使用Table扩展,但您可以通过在配置中更改markdown_extensions数组来管理所有扩展。

变更日志

请参阅变更日志

测试

要运行测试,请使用

$ composer test

贡献

安全

如果您发现任何安全相关的问题,请通过rathes@aheenam.com或使用GitHub的问题跟踪器发送电子邮件。

关于

Aheenam是德国NRW的一家小型公司,致力于创建定制的数字解决方案。访问我们的网站了解更多关于我们的信息。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件