forked from Brunojoe1994/-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontMatter.php
More file actions
46 lines (42 loc) · 1019 Bytes
/
FrontMatter.php
File metadata and controls
46 lines (42 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Strata\Data\Decode;
use Spatie\YamlFrontMatter\Document;
use Strata\Data\Data_DELETE\Item;
use Spatie\YamlFrontMatter\YamlFrontMatter as SpatieFrontMatter;
/**
* YAML Front matter decoder
*
* Front matter allows you to add variables at the top of a text file, in YAML format.
*
* E.g.
* ---
* title: example
* ---
*
* @see https://michelf.ca/projects/php-markdown/extra/
* @package Strata\Data\Filter
*/
class FrontMatter implements DecoderInterface
{
/**
* Parse content and return
*
* Return body content (with front matter stripped out):
* $item->body()
*
* Return front matter
* $item->title
*
* or:
* $item->matter('title')
*
* @param string|object $data
* @return Document Array of front matter or empty array on failure
*/
public function decode($data): Document
{
$data = StringNormalizer::getString($data);
return SpatieFrontMatter::parse($data);
}
}