Example #1
0
 public function testGetAttributes()
 {
     $attributes = ['title' => 'Hi Spress'];
     $item = new Item(Item::TYPE_PAGE, '/attributes');
     $item->setAttributes($attributes);
     $this->assertEquals($attributes, $item->getAttributes());
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     $items = [];
     foreach ($this->contents as $content) {
         if (isset($content['type']) === false) {
             continue;
         }
         if (isset($content['permalink']) === false) {
             continue;
         }
         $item = new Item($content['type'], $content['permalink']);
         if (isset($content['content']) === true) {
             $item->setContent($content['content']);
         }
         if (isset($content['content_extension']) === true) {
             $item->setContentExtension($content['content_extension']);
         }
         if (isset($content['title']) === true) {
             $item->setTitle($content['title']);
         }
         if (isset($content['date']) === true) {
             $item->setDate(new \DateTime($content['date']));
         }
         if (isset($content['attributes']) === true) {
             $item->setAttributes($content['attributes']);
         }
         $items[] = $item;
     }
     return $items;
 }
Example #3
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;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     $line = 1;
     $items = [];
     $isFirstRow = true;
     $reader = $this->buildCsvReader();
     $rows = $reader->fetchAssoc(['title', 'permalink', 'content', 'published_at', 'categories', 'tags', 'markup']);
     foreach ($rows as $row) {
         if ($this->options['not_header'] == false && $isFirstRow == true) {
             ++$line;
             $isFirstRow = false;
             continue;
         }
         $data = $this->resolveCsvRow($row, $line);
         $item = new Item(Item::TYPE_POST, $data['permalink']);
         $item->setDate($data['published_at']);
         $item->setContent($data['content']);
         $item->setTitle($data['title']);
         $item->setContentExtension($data['markup']);
         $attributes = [];
         if (count($data['categories']) > 0) {
             $attributes['categories'] = $data['categories'];
         }
         if (count($data['tags']) > 0) {
             $attributes['tags'] = $data['tags'];
         }
         $item->setAttributes($attributes);
         $items[] = $item;
         ++$line;
     }
     return $items;
 }