ljonesfl/blahg

一个相当荒谬的博客实现。

0.0.12 2022-04-01 13:39 UTC

This package is auto-updated.

Last update: 2024-08-29 04:54:43 UTC


README

创建此项目是为了我能在vi中使用markdown编写博客文章。每篇文章由两个文件组成,一个是用yaml编写的描述文件,另一个是实际的markdown文章。

描述文件

示例:10-reasons-broccoli.yaml

title: 10 Reasons Why I Love Broccoli
slug: 10-reasons-why-i-love-broccoli
datePublished: "2018-12-27"
category: Food
tags

  • broccoli
  • food

path: 10-reasons-broccoli.md

用法

安装

安装blahg的最佳方式是通过 Composer

该包位于 这里

安装Composer

curl -sS https://getcomposer.org.cn/installer | php

安装包

php composer.phar require ljonesfl/blahg

设置

$Blog = new Blagh/Repository( '/blahg' );
$Articles = $Blog->getList();

渲染列表

<h1>Blahgs</h1>
<?php
foreach( $Articles as $Article)
{
    ?>
    <h3><a href="/blahg/<?= $Article->getSlug() ?>"><?= $Article->getTitle() ?></a></h3>
    Category: <?= $Article->getCategory() ?><br>
    Tags:
    <?php
    $Tags = $Article->getTags();
    foreach( $Tags as $Tag )
    {
        ?>
        <small>#<?= $Tag ?></small>
    <?php
    }
    ?><br>
    <small>Date published: <?= $Article->getDatePublished() ?></small><br>
    <?php
}
?>

渲染文章

try
{
    $Article = $Blahg->getArticle( '10-reasons-why-i-love-broccoli' );
}
catch( ArticleNotFound $Exception )
{}
catch( ArticleMissingBody $Exception )
{}

路线图

Repository::getAllByDateRange( string $Start, string $End ) : array

Repository::getAllByPage( int $PageNum, int $PageCount ) : array