定制 jrean/blogit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jrean/blogit

Composer 安装命令:

composer require jrean/blogit

包简介

Blog with Git(hub). For Laravel 5.*. Fetch and Parse Documents hosted on Github.

README 文档

README

jrean/blogit is a PHP wrapper for the Github API (not yet Framework Agnostic) built for Laravel/Lumen to publish easily your content and "Blog with Git".

Goals

  • Leverage the power of the Github API
  • No database, no backoffice, no forms, ...
  • Open source your content and allow easy contributions
  • Write, Commit, Push, Live...

Installation

This project can be installed via Composer To get the latest version of Blogit, simply add the following line to the require block of your composer.json file:

"jrean/blogit": "~0.1.0"
// or
"jrean/blogit": "dev-master"

You'll then need to run composer install or composer update to download it and have the autoloader updated.

Add the Service Provider

Once Blogit is installed, you need to register the service provider.

Laravel

Open up config/app.php and add the following to the providers key:

  • 'Jrean\Blogit\BlogitServiceProvider'

Lumen

Open up bootstrap/app.php and add the following:

  • $app->register('Jrean\Blogit\BlogitServiceProvider');

Enable Dotenv File (Lumen only)

Uncomment the following line in bootstrap/app.php:

// Dotenv::load(__DIR__.'/../');

Configuration

Update your .env file with the following keys and assign your values:

GITHUB_USER                    =your_github_user_name
GITHUB_TOKEN                   =your_github_token
GITHUB_REPOSITORY              =your_repository_name
GITHUB_ARTICLES_DIRECTORY_PATH =content_root_directory_name
  • GITHUB_TOKEN

Your Github username.

  • GITHUB_TOKEN

Visit Github and create a Personal Access Tokens

  • GITHUB_REPOSITORY

Create a new Public repository or use an existing one.

  • GITHUB_ARTICLES_DIRECTORY_PATH

Inside your repository create a directory (for instance articles) where you will push your files.

Basic usage

Without Controller

Update app/Http/routes.php:

$app->get('/blogit', function() use($app) {

    // Jrean\Blogit\Blogit instance
    $blogit   = $app->make('blogit');

    // Jrean\Blogit\BlogitCollection
    $articles = $blogit->getArticles();

    // Last 3 created Articles
    $news     = $articles->sortByCreatedAtDesc()->take(3);

    // Last 3 updated Articles
    $updates  = $articles->sortByUpdatedAtDesc()->take(3);

    return view('blogit.index', compact('news', 'updates')); });

$app->get('/blogit/{slug}', function($slug) use($app) {

    // Jrean\Blogit\Blogit instance
    $blogit  = $app->make('blogit');

    // Jrean\Blogit\Document\Article
    $article = $blogit->getArticleBySlug($slug);

    if ($article === null) abort(404);

    return view('blogit.show', compact('article'));
});

With Controller

Update app/Http/routes.php:

$app->get('/', [
    'uses' => 'App\Http\Controllers\YourController@index',
    'as'   => 'index'
]);

$app->get('/{slug}', [
    'uses' => 'App\Http\Controllers\YourController@show',
    'as'   => 'show'
]);

Update app/Http/Controllers/YourController.php:

<?php
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Jrean\Blogit\Repository\DocumentRepositoryInterface;

class YourController extends Controller {

    private $blogit;

    public function __construct(DocumentRepositoryInterface $blogit)
    {
        $this->blogit = $blogit;
    }

    public function index()
    {
        $articles = $this->blogit->getArticles();
        $news     = $articles->sortByCreatedAtDesc()->take(3);
        $updates  = $articles->sortByUpdatedAtDesc()->take(3);

        return view('blogit.index', compact('news', 'updates'));
    }

    public function show($slug)
    {
        $article = $this->blogit->getArticleBySlug($slug);

        if ($article === null) abort(404);

        return view('blogit.show', compact('article'));
    }
}

Views (Blade for instance)

@foreach($articles as $article)
    {{ $article->getTitle() }}
    {{ $article->getSlug() }}
    {{ $article->getLastCommitUrl() }}
    {{ $article->getUpdatedAtDiff() }}
    {{ $article->getTags() }}
    {{ $article->getHtml() }}
    {{ $article->getContributors() }}
    ...
@endforeach

Basic File Format

I recommand to stick with .md files:

title: My Article Title
slug: my-custom-slug
tags: [tag, tag, tag]
---
## My Markdown Content

The .md file contains two sections separated by a delimiter string. One section for the metadata and one for the content.

Delimiter String

To separate metadata and content you MUST use a minimum of three ---. You can use more if you want.

Metadata

Metada will be parsed as Yaml so feel free and creative because you'll access them through an array. The only required key is the title. slug and tags are optionnals. If you don't provide a custom slug, one will be auto generated based on the title value...

Content

Everything under --- will be parsed as Markdown. Again, fell free and creative.

Extending and Customize Blogit

I try and will try my best to give you the ability to extend and override Blogit. For now you can easily hack and extend Jrean\Blogit\Blogit.php and Jrean\Blogit\BlogitCollection.php to bring your own logic, methods and attributes.

Be Creative

With the Blogit API you have access to methods and properties about your content, metadata, commits, contributors, tags, dates, Github links,... Have a look at Jrean\Blogit\Document\*, Jrean\Blogit\Repository\* and Jrean\Blogit\Blogit.php.

Contribute

This package is (yet) under active development and refactoring. Please, feel free to comment, contribute and help. I would like/love to bring Unit tests.

Example

I will write soon a dedicated article for Blogit which is now used on Production for Askjong.com

License

Blogit is licensed under The MIT License (MIT).

jrean/blogit 适用场景与选型建议

jrean/blogit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 71 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「blog」 「git」 「markdown」 「github」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jrean/blogit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jrean/blogit 我们能提供哪些服务?
定制开发 / 二次开发

基于 jrean/blogit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 71
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-14