Ejemplo n.º 1
0
 /**
  * MarkdownFileBuilder constructor.
  *
  * @param Filesystem $filesystem
  * @param Factory $viewFactory
  */
 public function __construct(Filesystem $filesystem, Factory $viewFactory, SplFileInfo $file, array $data)
 {
     $this->filesystem = $filesystem;
     $this->viewFactory = $viewFactory;
     $this->file = $file;
     $this->data = $data;
     $parsed = Markdown::parseWithYAML($this->file->getContents());
     $this->fileContent = $parsed[0];
     $this->fileYAML = $parsed[1];
     $this->cached = KATANA_CACHE_DIR . '/' . sha1($this->file->getRelativePathname()) . '.php';
     $this->bladeCompiler = $this->getBladeCompiler();
     $this->engine = $this->getEngine();
 }
Ejemplo n.º 2
0
 /**
  * Get the blog post data.
  *
  * @param SplFileInfo $file
  *
  * @return \stdClass
  */
 public function getPostData(SplFileInfo $file)
 {
     $this->file = $file;
     if ($this->file->getExtension() == 'md') {
         $postData = Markdown::parseWithYAML($this->file->getContents())[1];
     } else {
         $view = $this->viewFactory->make(str_replace('.blade.php', '', $this->file->getRelativePathname()));
         $postData = [];
         $view->render(function ($view) use(&$postData) {
             $postData = $view->getFactory()->getSections();
         });
     }
     // Get only values with keys starting with post::
     $postData = array_where($postData, function ($key) {
         return starts_with($key, 'post::');
     });
     // Remove 'post::' from $postData keys
     foreach ($postData as $key => $val) {
         $postData[str_replace('post::', '', $key)] = $val;
         unset($postData[$key]);
     }
     $postData['path'] = str_replace(KATANA_PUBLIC_DIR, '', $this->getDirectoryPrettyName()) . '/';
     return json_decode(json_encode($postData), false);
 }