public function testSlug() { $this->assertEquals('welcome-to-spress', Str::slug('Welcome to Spress')); $this->assertEquals('bienvenido-a-espana', Str::slug('Bienvenido a España')); $this->assertEquals('version-2-0-0', Str::slug('version 2.0.0')); $this->assertEquals('hello-spress', Str::slug('hello spress')); $this->assertEquals('hello-spress', Str::slug('-hello-spress-')); $this->assertEquals('12-cheese', Str::slug('1\\2 cheese')); $this->assertEquals('2-step', Str::slug('.,;{}+¨¿?=()/&%$·#@|!ºª2 step ^[]')); }
/** * 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; }