phly / phly-blog
此包最新版本(2.1.1)没有可用的许可证信息。
实现静态博客生成器的Laminas模块
2.1.1
2020-11-09 14:53 UTC
Requires
- php: ^7.3
- laminas/laminas-cli: ^0.1.4
- laminas/laminas-console: ^2.5
- laminas/laminas-dependency-plugin: ^1.0 || ^2.0
- laminas/laminas-eventmanager: ^3.0
- laminas/laminas-feed: ^2.5
- laminas/laminas-filter: ^2.5
- laminas/laminas-http: ^2.5
- laminas/laminas-i18n: ^2.5
- laminas/laminas-inputfilter: ^2.5
- laminas/laminas-modulemanager: ^2.5
- laminas/laminas-mvc: ^3.0
- laminas/laminas-paginator: ^2.5
- laminas/laminas-stdlib: ^3.0
- laminas/laminas-tag: ^2.5
- laminas/laminas-uri: ^2.5
- laminas/laminas-validator: ^2.5
- laminas/laminas-view: ^2.5
- phly/phly-common: ^2.0.1
- symfony/console: ^5.1
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^9.4
This package is auto-updated.
Last update: 2024-09-09 22:57:24 UTC
README
此模块是生成静态博客的工具。
博客文章是简单的PHP文件,创建并返回 PhlyBlog\EntryEntity
对象。您将编译器指向一个目录,它将创建一个代表您的博客及其源的数据文件树。这些文件可以由您的应用程序消费,或者它们可以是您直接服务的纯旧HTML标记文件。
要求
- PHP >=
7.3
- 需要Laminas包,特别是
- laminas/laminas-view,用于渲染和写入生成的文件。
- laminas/laminas-mvc 和 laminas/laminas-modulemanager,因为这是一个模块,编译器脚本依赖于它和laminas-mvc
Application
实例。因此,它还依赖于 laminas/laminas-servicemanager 和 laminas/laminas-eventmanager。 - laminas/laminas-feed 用于生成源。
- laminas/laminas-tag 用于生成标签云。
- phly/phly-common 用于实体和过滤器接口。
安装
使用 Composer 将此模块添加到您的应用程序
$ composer require phly/phly-blog
编写条目
在您的存储库中找到一个条目的位置,最好在您的文档根目录之外;我建议使用 data/blog/
或 posts/
。
帖子文件是简单的PHP文件,返回一个 PhlyBlog\EntryEntity
实例。一个示例在 misc/sample-post.php
中提供。这个帖子可以作为模板复制。
需要注意的重要事项
- 设置创建和/或更新的时间戳。或者,使用
DateTime
或date()
根据日期/时间字符串生成时间戳。 - 标记为“草稿”的条目(即,
setDraft(true)
)将不会发布。 - 标记为私有的条目(即,
setPublic(false)
)将发布,但不会聚合到分页视图或源中。因此,您需要将URL提供给某人,以便他们可以看到它。 - 您可以设置一组标签。标签可以有空白,这将被转换为“+”字符。
用法
此模块提供了 laminas/laminas-cli 工具。
运行
$ ./vendor/bin/laminas help phly-blog:compile
以获取用法。目前,编译工具可以生成以下工件
- 每个条目一个文件
- 分页条目文件
- 按年份分页的条目文件
- 按月份分页的条目文件
- 按天分页的条目文件
- 按标签分页的条目文件
- 最近条目的Atom和/或RSS源
- 按标签分页的最近条目的Atom和/或RSS源
- 可选地,一个标签云
您需要设置本地配置;我建议将其放在 config/autoload/blog.global.php
中。以下是一个示例
<?php return [ 'blog' => [ 'options' => [ // The following indicate where to write files. Note that this // configuration writes to the "public/" directory, which would // create a blog made from static files. For the various // paginated views, "%d" is the current page number; "%s" is // typically a date string (see below for more information) or tag. 'by_day_filename_template' => 'public/blog/day/%s-p%d.html', 'by_month_filename_template' => 'public/blog/month/%s-p%d.html', 'by_tag_filename_template' => 'public/blog/tag/%s-p%d.html', 'by_year_filename_template' => 'public/blog/year/%s-p%d.html', 'entries_filename_template' => 'public/blog-p%d.html', // In this case, the "%s" is the entry ID. 'entry_filename_template' => 'public/blog/%s.html', // For feeds, the final "%s" is the feed type -- "atom" or "rss". In // the case of the tag feed, the initial "%s" is the current tag. 'feed_filename' => 'public/blog-%s.xml', 'tag_feed_filename_template' => 'public/blog/tag/%s-%s.xml', // This is the link to a blog post 'entry_link_template' => '/blog/%s.html', // These are the various URL templates for "paginated" views. The // "%d" in each is the current page number. 'entries_url_template' => '/blog-p%d.html', // For the year/month/day paginated views, "%s" is a string // representing the date. By default, this will be "YYYY", // "YYYY/MM", and "YYYY/MM/DD", respectively. 'by_year_url_template' => '/blog/year/%s-p%d.html', 'by_month_url_template' => '/blog/month/%s-p%d.html', 'by_day_url_template' => '/blog/day/%s-p%d.html', // These are the primary templates you will use -- the first is for // paginated lists of entries, the second for individual entries. // There are of course more templates, but these are the only ones // that will be directly referenced and rendered by the compiler. 'entries_template' => 'phly-blog/list', 'entry_template' => 'phly-blog/entry', // The feed author information is default information to use when // the author of a post is unknown, or is not an AuthorEntity // object (and hence does not contain this information). 'feed_author_email' => 'you@your.tld', 'feed_author_name' => "Your Name Here", 'feed_author_uri' => 'http://your.tld', 'feed_hostname' => 'http://your.tld', 'feed_title' => 'Blog Entries :: Your Blog Name', 'tag_feed_title_template' => 'Tag: %s :: Your Blog Name', // If generating a tag cloud, you can specify options for // Laminas\Tag\Cloud. The following sets up percentage sizing from // 80-300% 'tag_cloud_options' => ['tagDecorator' => [ 'decorator' => 'html_tag', 'options' => [ 'fontSizeUnit' => '%', 'minFontSize' => 80, 'maxFontSize' => 300, ], ]], ], // This is the location where you are keeping your post files (the PHP // files returning `PhlyBlog\EntryEntity` objects). 'posts_path' => 'data/posts/', // Tag cloud generation is possible, but you likely need to capture // the rendered cloud to inject elsewhere. You can do this with a // callback. // The callback will receive a Laminas\Tag\Cloud instance, the View // instance, application configuration // (as an array), and the // application's Locator instance. 'cloud_callback' => ['Application\Module', 'handleTagCloud'], ], 'view_manager' => [ // You will likely want to customize the templates provided. Do so by // creating your own in your own module, and make sure you alter the // resolvers so that they point to the override locations. Below, I'm // putting my overrides in my Application module. 'template_map' => [ 'phly-blog/entry-short' => 'module/Application/view/phly-blog/entry-short.phtml', 'phly-blog/entry' => 'module/Application/view/phly-blog/entry.phtml', 'phly-blog/list' => 'module/Application/view/phly-blog/list.phtml', 'phly-blog/paginator' => 'module/Application/view/phly-blog/paginator.phtml', 'phly-blog/tags' => 'module/Application/view/phly-blog/tags.phtml', ], 'template_path_stack' => [ 'phly-blog' => 'module/Application/view', ], ], ];
当您运行命令行工具时,它将在您配置中指定的位置生成文件。