PHPackages                             ljonesfl/blahg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ljonesfl/blahg

ActiveLibrary

ljonesfl/blahg
==============

A largely ridiculous blog implementation.

0.5.2(9mo ago)0191MITPHPPHP 8.\*.\*

Since Mar 28Pushed 9mo agoCompare

[ Source](https://github.com/ljonesfl/blahg)[ Packagist](https://packagist.org/packages/ljonesfl/blahg)[ RSS](/packages/ljonesfl-blahg/feed)WikiDiscussions develop Synced today

READMEChangelogDependencies (4)Versions (25)Used By (0)

Blahg
=====

[](#blahg)

A lightweight PHP library for creating blog applications with Markdown content and YAML metadata.

Features
--------

[](#features)

- **Markdown-based content** - Write articles in Markdown with GitHub-flavored markdown and footnote support
- **YAML metadata** - Organize articles with YAML descriptors containing title, tags, categories, and more
- **Draft management** - Control article visibility with draft status
- **RSS feed generation** - Automatic RSS feed creation for your blog
- **Flexible querying** - Filter articles by tag, category, author, or slug
- **Future publishing** - Schedule articles with future publication dates

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- Composer

Installation
------------

[](#installation)

Install via [Composer](http://getcomposer.org):

```
composer require ljonesfl/blahg
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

```
use Blahg\Repository;

// Initialize repository with your content directory
$repository = new Repository('/path/to/articles');

// Get all published articles
$articles = $repository->getArticles();
```

### Article Structure

[](#article-structure)

Each article consists of two files:

1. **YAML descriptor** (e.g., `my-article.yaml`)
2. **Markdown content** (e.g., `my-article.md`)

#### YAML Descriptor Example

[](#yaml-descriptor-example)

```
title: "10 Reasons Why I Love Broccoli"
slug: "10-reasons-why-i-love-broccoli"
datePublished: "2018-12-27"
category: "Food"
author: "John Doe"
description: "A deep dive into the wonderful world of broccoli"
tags:
  - broccoli
  - vegetables
  - nutrition
path: "10-reasons-broccoli.md"
draft: false
githubFlavored: true
canonicalUrl: "https://example.com/blog/10-reasons-why-i-love-broccoli"
```

#### Required Fields

[](#required-fields)

- `title` - Article title
- `slug` - URL-friendly identifier
- `datePublished` - Publication date (YYYY-MM-DD format)
- `path` - Path to the Markdown content file

#### Optional Fields

[](#optional-fields)

- `category` - Article category
- `tags` - Array of tags
- `author` - Article author
- `description` - Short description for meta tags
- `draft` - Set to `true` to hide from public view
- `githubFlavored` - Enable GitHub-flavored Markdown
- `canonicalUrl` - Canonical URL for SEO

### Retrieving Articles

[](#retrieving-articles)

```
// Get all published articles (excludes drafts and future posts)
$articles = $repository->getArticles();

// Get a specific article by slug
try
{
    $article = $repository->getArticle('10-reasons-why-i-love-broccoli');
}
catch( ArticleNotFound $e )
{
    // Handle missing article
}
catch( ArticleMissingBody $e )
{
    // Handle missing content file
}

// Include drafts in results
$repository->setShowDrafts( true );
$allArticles = $repository->getArticles();
```

### Filtering Articles

[](#filtering-articles)

```
// Get articles by category
$foodArticles = $repository->getArticlesByCategory( 'Food' );

// Get articles by tag
$broccoliArticles = $repository->getArticlesByTag( 'broccoli' );

// Get articles by author
$johnsArticles = $repository->getArticlesByAuthor( 'John Doe' );
```

### Getting Metadata

[](#getting-metadata)

```
// Get all unique categories
$categories = $repository->getCategories();

// Get all unique tags
$tags = $repository->getTags();

// Get all unique authors
$authors = $repository->getAuthors();
```

### Rendering Articles

[](#rendering-articles)

#### Article List Example

[](#article-list-example)

```
Blog Articles
