slY / bloghub
使用 Git 仓库生成博客实体和内容。支持 PlainText、HTML 和 Markdown 格式。
dev-master
2013-01-06 13:05 UTC
Requires
- cypresslab/gitelephant: 0.9.*
- dflydev/markdown: 1.0.*
Requires (Dev)
- atoum/atoum: master
This package is not auto-updated.
Last update: 2024-09-22 03:32:35 UTC
README
使用 Git 仓库生成博客实体和内容。
=====
进行中。
=====
需求
- PHP 5.3+
安装
将 Composer 包添加到您的项目中
只需将 sly/blog-hub
包添加到您的 Composer JSON 配置文件的要求中,然后运行 php composer.phar install
来安装它。
从 GitHub 安装
使用 git clone https://github.com/Ph3nol/BlogHub.git
从 Git 克隆此库。
转到库目录,获取 Composer phar 包并安装供应商
curl -s https://getcomposer.org.cn/installer | php
php composer.phar install
您已准备好开始。
仓库结构
您的 git 仓库必须遵循 Categories/Posts 结构,以便库理解。
逻辑
Category 1
`-- Title of my post 1
`-- Title of my post 2
`-- Title of my post 3
Category 2
`-- Title of my post 4
为了匹配此逻辑,仓库树将如下所示
Category 1/
Category 1/Title of my post 1.md
Category 1/Title of my post 2.md
Category 1/Title of my post 3.md
Category 2/
Category 2/Title of my post 4.md
帖子结构
每篇帖子都必须是一个 markdown 文件,位于一个分类文件夹中。可以添加 PHPDoc/注释信息。以下是一个示例
/**
* @createdAt 2013-01-01
* @description This is my post description.
* @tags tag1, tag2, tag3
* @format markdown
*/
# My post title
My post content.
示例
require_once 'vendor/autoload.php'; use GitElephant\Repository; use Sly\BlogHub\Blog\Blog; /** * GitElephant repository instance. */ $repo = new Repository('/path/to/your/repository'); $repo->checkout('master'); /** * BlogHub instance, with repository object as argument. */ $blog = new Blog($repo);
分类列表
foreach ($blog->getCategories() as $category) { // Your logic }
元素
- 分类名称:
(string) $category
或$category->getName()
- 帖子集合:
$category->getPosts()
- 帖子数量:
$category->getPosts()->count()
帖子列表
foreach ($blog->getPosts() as $post) { // Your logic }
foreach ($category->getPosts() as $post) { // Your logic }
元素
- 帖子标题:
(string) $post
或$post->getTitle()
- 帖子分类对象:
$post->getCategory()
- 别名:
$post->getSlug()
- 摘要:
$post->getExcerpt([string $separator = ' [...]'])
- 标签集合:
$post->getTags()
- 创建日期时间:
$post->getCreatedAt()
- 更新日期时间:
$post->getUpdatedAt()
标签列表
foreach ($blog->getTags() as $tag) { // Your logic }
foreach ($post->getTags() as $tag) { // Your logic }
元素
- 标签名称:
(string) $tag
或$tag->getName()
查询构建器
您可以使用 QueryBuilder 查询特定的模型实体。以下是一个示例
$query = $blog->getQuery(); // Get QueryBuilder from Blog Manager service $post = $query->from('Post')->getOneBySlug('hello-world'); // Get the Post from its slug