Example #1
0
 public function testSetContentExtension()
 {
     $item = new Item(Item::TYPE_PAGE, '/about');
     $item->setContentExtension('md');
     $this->assertEquals('md', $item->getContentExtension());
 }
Example #2
0
 /**
  * Process a post item.
  *
  * @param Item $item The item.
  *
  * @throws RuntimeException If date or title are missing.
  */
 protected function processPostItem(Item $item)
 {
     if (is_null($item->getDate())) {
         throw new \RuntimeException(sprintf('Date in post item: "%s" is required.', $item->getPermalink()));
     }
     if (empty($item->getTitle())) {
         throw new \RuntimeException(sprintf('Title in post item: "%s" is required.', $item->getPermalink()));
     }
     $urlPath = $this->getPathFromPermalink($item->getPermalink());
     $attributes = $item->getAttributes();
     $permalinkAttr = $this->normalizedPathToPermalink($urlPath);
     if (empty($permalinkAttr) == false) {
         $attributes['permalink'] = $permalinkAttr;
     }
     $attributes['no_html_extension'] = true;
     $item->setAttributes($attributes);
     $filenameExtension = $item->getContentExtension();
     $slugedTitle = Str::slug($item->getTitle());
     $filename = sprintf('%s-%s.%s', $item->getDate()->format('Y-m-d'), $slugedTitle, $filenameExtension);
     $relativePath = $this->sanitizePath('content/posts/' . $filename);
     $fileExists = file_exists($this->getSrcPath($relativePath));
     $spressContent = $this->getSpressContent($item);
     $resultItem = new ResultItem($item->getPermalink(), $spressContent, $fileExists);
     $resultItem->setRelativePath($relativePath);
     $resultItem->setPermalink($permalinkAttr);
     $this->postAndPageItems[] = $resultItem;
     $this->impotedItems[] = $resultItem;
 }