Flat file content management package for PHP.

dev-master 2014-03-25 19:00 UTC

This package is not auto-updated.

Last update: 2024-04-27 12:59:44 UTC


README

Thin is a package for flat file content management. By default, it supports files in Markdown and Markdown Extra format.

Installation

Install Thin from Packagist:

"petersuhm/thin": "dev-master"

Usage

You can make your own implementations, depending on your type of content and which parser you want to use (it's Markdown by default). By default, Thin comes with two parsers, one for Markdown and one for Markdown Extra, and one model to handle blog posts.

$postLoader = new \Thin\PostLoader;

$postLoader->config(array(
    'document_path' = '../posts',
    'document_ext' = '.md'
));

// Returns a DocumentCollection
$posts = $postLoader->all();

// You can limit the number of documents
$posts->limit(5);

// You can also order documents by metadata
$posts->orderBy('date', 'desc');
$posts->orderBy('date', 'desc')->limit(3);

foreach ($posts as $post)
{
    $post->getMetadata('title');
    $post->getContent();
    $post->getHtmlContent();

    // Metadata can be accessed dynamically as well:
    $post->title;

    // Optionally give an instance of ParserInterface as a parameter
    $post->getHtmlContent(new \Thin\Parsers\MarkdownExtraParser);

}

// The PostLoader uses a slug as identifier
$post = $postLoader->find('some-slug');

The PostLoader expects files to follow the following convention:

{
    "some_metadata": "In JSON format",
    "...": "..."
}

The content of the document.

If your files have a different format, you can write your own loader.