<?php
|
|
namespace App\Services;
|
|
|
|
use Mni\FrontYAML\Parser;
|
|
use Spatie\YamlFrontMatter\YamlFrontMatter;
|
|
|
|
class ReplaceBlogService {
|
|
public function replaceFrontMatter($path = "")
|
|
{
|
|
$parser = new Parser();
|
|
if (is_dir($path)) {
|
|
$files = scandir($path);
|
|
foreach ($files as $file) {
|
|
if ($file == "." || $file == ".." | $file == ".DS_Store") {
|
|
continue;
|
|
}
|
|
$object = YamlFrontMatter::parse(file_get_contents($path . "/" . $file));
|
|
|
|
dump($object->matter());
|
|
dump($object->matter('title')); // => 'Example';
|
|
// dump($object->body()); // => 'Lorem ipsum.'
|
|
|
|
|
|
dump($object->title); // => 'Example';
|
|
// $document = $parser->parse($path . "/" . $file);
|
|
|
|
// $yaml = $document->getYAML();
|
|
// dump($yaml);
|
|
// $html = $document->getContent();
|
|
// dump($html);
|
|
// exit;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|