简约的Markdown博客工具

v1.0-alpha 2014-08-18 09:58 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:57:46 UTC


README

专注于使用简单的Markdown编写干净的博客文章。包括人们会喜欢的美丽多彩的代码块。

简约方法,基于silex。选择存储和检索Markdown的位置,我使用单独的git仓库。文章被推送到这里,并通过FileArticleService进行映射。

用法

为您的应用程序

  • 添加到您的composer
  • 添加到您的Silex应用程序
  • 安装 Pygments
  • 指定pygmentize的bin路径
  • 指定文章的路径(默认文件提供者)

Composer

{
    "require": {
        "cammanderson/mmb" : "dev-master"
    }
}

Silex服务提供者和路由

您可以将文章服务添加到应用程序中,并在需要时使用它。

...
$app->register(new MMB\ArticleServiceProvider());
...
// Controller
$articleController = function (Silex\Application $app, MMB\Article $article) {
    return $app['twig']->render('article.html.twig', array(
            'article' => $article,
            'highlighter' => $app['markdown_parser_highlighter']
        ));
};

// Add the article route
$app->get('/article/{article}', function (MMB\Article $article) use ($app, $articleController) {
    return $articleController($app, $article);
})->assert('article', '.+')
->convert('article', 'article_service:getArticle');
...

默认配置

当前需要设置app['config']['parameters']中的几个元素

parameters:
    mmb_file_path: ../content
    pygments_bin: /opt/local/bin/pygmentize-2.7

考虑使用silex的YAML配置提供程序 deralex/yaml-config-service-provider

撰写文章

使用FileArticleService,它将查找配置路径来查找文件。文章通过键进行映射,键与文件名匹配。

2014-08-10_my-article.md
2014-08-12_my-other-article.md

托管文章在GitHub上

将文章放置在GitHub仓库中并通过mmd的GithubService连接是很容易的。

扩展

文章的替代位置

您始终可以实现自己的ArticleService来从其他位置获取文章。

class MyArticleService extends AbstractArticleService
{
    public function getArticle($key)
    {
        // TODO: Implement your own method to locate the article
        $articleContents = '...';

        // Create the article
        $article = $this->provider->provide($key, $articleContents);

        // ... Apply further properties your Service supports

        // Return
        return $article;
    }
}

现在将其注册到依赖注入器中(请记住提供文章提供者)。

$app['article_service'] = $app->share(function ($app) {
    $service = new MyArticleService();
    $service->setProvider($app['article_provider']);
    return $service;
});

待办事项

最终将移至MCB(Minimalist Coders Blog)以供更广泛的使用。开发者可以实施自己的文章提供程序(文件、git、cmf等)、格式化和高亮显示(例如pygments、geshi等)。

  • 向文章添加各种特质以支持日期、作者、版本、更改日志等
  • 实现GitArticleService/GitHubArticleService以查询git的作者、版本等
  • 实现更好的配置布局
  • 实现ArticleService列表命令,允许列出博客历史记录
  • 通过DI/服务容器配置可能的Symfony2支持
  • 实现geshi/sundown/restructedtext等。