https://github.com/settermjd/markdown-blog
A small package that will convert Markdown files with YAML frontmatter into a list of blog item objects.
https://github.com/settermjd/markdown-blog
Last synced: about 1 year ago
JSON representation
A small package that will convert Markdown files with YAML frontmatter into a list of blog item objects.
- Host: GitHub
- URL: https://github.com/settermjd/markdown-blog
- Owner: settermjd
- Created: 2022-01-04T12:10:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-20T12:20:21.000Z (almost 2 years ago)
- Last Synced: 2025-02-14T00:51:37.618Z (over 1 year ago)
- Language: PHP
- Size: 285 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Markdown Blog
This is a Markdown-based blog module, one that does just the basics of converting a series of, minimalist, Markdown files with Yaml front-matter into an array of BlogArticle entities.
These entities can be used to provide a list of blog articles, or to render a given article.
## Usage
### Use standalone
The code can be used standalone or as part of code in larger, likely framework-based, setup.
If you want to use the code standalone, you need to first create a series of Markdown files that have YAML front-matter.
Then, you can use the code below as a starting point, to convert the Markdown files into BlogArticle entities, which you can then paginate over or render individually using the templating engine of choice (if you are using one).
```php
require_once '../vendor/autoload.php';
$itemLister = new \MarkdownBlog\Items\Adapter\ItemListerFilesystem(
__DIR__ . '/../data/posts',
new \Mni\FrontYAML\Parser()
);
/** @var \MarkdownBlog\Entity\BlogArticle $item */
$items = $itemLister->getArticles();
```
### Use as part of a framework
If you are using the code as part of a framework, ideally one that implements [PSR-11](https://www.php-fig.org/psr/psr-11/), such as Mezzio, then you can take a slightly different approach.
In this case, first add a configuration entry to your application's configuration that has the following structure.
```php
use Mni\FrontYAML\Parser;
return [
'blog' => [
'type' => 'filesystem',
'path' => __DIR__ . '/../../data/posts',
'parser' => new Parser(),
]
];
```
Then, in your DI container, add an entry where the key is `ItemListerInterface::class` and the value is `ItemListerFactory`.
The example below shows how to do this when using Mezzio.
```php
'factories' => [
\MarkdownBlog\Items\ItemListerInterface::class => \MarkdownBlog\Items\ItemListerFactory::class,
]
```
This will then instantiate an `ItemListerInterface` object, based on your configuration and make it available to your application, when retrieved.
Then, use it as in the standalone version above, such as in the example below.
```php
/** @var \MarkdownBlog\Entity\BlogArticle $item */
$items = $itemLister->getArticles();
```