/** * Create an article. * * Returns path to the created markdown file. * * @param string $title Title of the article. * @param string $slug [optional] Slug of the article. If ommitted, it will be built based on the title. * @param string $image [optional] Path to cover image, relative to the web root folder. * * @return string */ public function create($title, $slug = null, $image = null) { $slug = $slug ? StringUtils::urlFriendly($slug) : StringUtils::urlFriendly($title); $articles = $this->reader->load(); // check if maybe there already is such article if (ArrayUtils::search($articles, 'slug', $slug) !== false) { throw new NotUniqueException('There already is a blog article with a slug "' . $slug . '".'); } // create a markdown post $markdown = $title . NL . '==========' . NL . date('Y-m-d') . NL . ($image ? '![cover](' . $image . ')' . NL : '') . NL; $markdownFile = $this->articlesDir . $slug . '.md'; // create the articles directory if doesn't exist $this->filesystem->dumpFile($markdownFile, $markdown); // add to articles array array_unshift($articles, array('slug' => $slug, 'title' => $title)); $this->writer->write($this->dataFile, $articles); return $markdownFile; }
/** * Returns an article based on a slug. * * @param string $slug Article slug. * * @return Article */ public function getArticle($slug) { return $this->reader->getArticle($slug); }
/** * Queues articles to be generated. */ public function queueArticlesToGenerate() { foreach ($this->reader->getArticles() as $article) { $this->genry->addToQueue($this->template, array('article' => $article), $this->targetDir . $article->getSlug() . '.html'); } }