roelofjan-elsinga/flat-file-cms

此包已被弃用且不再维护。作者建议使用roelofjan-elsinga/aloia-cms包。

Laravel的嵌入式扁平文件CMS。


README

CI StyleCI Status Code Coverage Total Downloads Latest Stable Version License

此包包含一个嵌入式CMS,它使用文件存储其内容。

有关完整文档,请访问Aloia CMS 文档网站。

安装

您可以通过Composer使用以下命令包含此包:

composer require roelofjan-elsinga/aloia-cms

如果您想自定义文件夹结构,则可以通过以下命令发布配置:

php artisan vendor:publish --provider="AloiaCms\\AloiaCmsServiceProvider"

创建自定义内容类型

创建自定义内容类型非常简单。您只需创建一个扩展AloiaCms\Models\Model的类,指定一个$folder_path,并可选地添加到$required_fields中所需字段。以下是一个示例:

namespace App\Models;

use AloiaCms\Models\Model;

class PortfolioItem extends Model
{
    protected $folder = 'portfolio_items';

    protected $required_fields = [
        'name',
        'github_url',
        'description',
    ];
}

一旦您有这样一个类,您就可以像“模型使用”部分中描述的那样与之交互。

内置模型

有4个内置模型,您可以在不进行任何额外设置的情况下使用。

  • 页面
  • 文章
  • 内容块
  • 元标签

当然,您可以像“创建自定义内容类型”部分中描述的那样添加您自己的模型。

模型使用

在这个例子中,我们查看一个内置的内容类型:文章。您可以使用这些相同的步骤为所有从"AloiaCms\Models\Model"扩展的类执行。

要加载在config('aloiacms.collection_path')中指定的文件夹中的“articles”文件夹中的所有文章,您可以使用以下脚本:

use AloiaCms\Models\Article;

/**@var Article[]*/
$articles = Article::all();

您可以使用它来显示您的内容。您还可以加载单个文章,使用:

$post_slug = 'this-post-is-amazing';

$article = Article::find($post_slug);

如果您只想加载所有已发布的文章,您需要像这样检索它们:

$published_articles = Article::published();

要获取每篇文章的原始内容(内容+元数据),您可以使用:

$post_slug = 'this-post-is-amazing';

$articles = Article::find($post_slug)->rawContent();

最后,要更新您的文章,您可以运行:

use Carbon\Carbon;

$post_slug = 'this-post-is-amazing';

Article::find($post_slug)
    ->setExtension('md') // md is the default, but you can use html as well.
    ->setMatter([
        'description' => 'This post is about beautiful things',
        'is_published' => true,
        'is_scheduled' => false,
        // Either use post_date in setMatter() or setPostDate()
        'post_date' => date('Y-m-d')
    ])
    ->setPostDate(Carbon::now())
    ->setBody('# This is the content of an article')
    ->save();

内容块

您可以通过此包管理您网站上的小型内容块。

块的内容存储在config('aloiacms.collections_path')文件夹中的“content_blocks”文件夹中。

您需要将门面注册到您的应用程序中,方法是在config/app.php中的别名中放置以下行:

'Block' => \AloiaCms\Facades\BlockFacade::class,

现在您可以在blade视图中使用门面,使用以下命令:

{!! Block::get('content-file-name') !!}

此门面将在您在config('aloiacms.collections_path')中指定的文件夹中查找文件。门面将解析文件的包含内容到HTML以便能够渲染。如果没有找到文件,将返回空字符串。

注意:您不应指定传递给Block::get()的文件名的扩展名。这将被自动解析。

测试

您可以通过在终端中运行 ./vendor/bin/phpunit 来执行包含的测试。

贡献

如果您想直接为CMS做出贡献,您可以在本仓库创建PR。如果您想为文档做出贡献,您可以在文档仓库创建PR。