/** * @param Directory $parent * @param SplFileInfo $file * @return Content|Raw */ public static function createContent(Directory $parent, SplFileInfo $file) { $name = static::getName($file->getPathname()); $config = $parent->getConfig(); if (!in_array($file->getExtension(), $config['valid_content_extensions'])) { $uri = static::removeSortingInformations($file->getFilename()); $entry = new Raw($parent, $uri, $file); $entry->setTitle(str_replace('_', ' ', static::removeSortingInformations($name))); $entry->setName($name); return $entry; } $uri = static::removeSortingInformations($name); if ($config->isStatic()) { $uri .= '.html'; } $entry = new Content($parent, $uri, $file); if ($entry->getUri() == $config['index_key']) { if ($parent instanceof Root) { $entry->setTitle($config['title']); } else { $entry->setTitle($parent->getTitle()); } } else { $entry->setTitle(str_replace('_', ' ', static::removeSortingInformations($name))); } $entry->setName($name); return $entry; }
/** * @param Directory $parent * @param string $path * @return Content */ public static function getOrCreatePage(Directory $parent, $path) { $title = static::getName($path); // If the file doesn't have an extension, set .md as a default if (pathinfo($path, PATHINFO_EXTENSION) == '') { $path .= '.md'; } $uri = $slug = DauxHelper::slug($title); if ($parent->getConfig()['mode'] === Daux::STATIC_MODE) { $uri = $slug . ".html"; } if (array_key_exists($uri, $parent->getEntries())) { return $parent->getEntries()[$uri]; } $page = new Content($parent, $uri); $page->setContent("-"); //set an almost empty content to avoid problems if ($title == 'index') { // TODO :: clarify the difference between 'index' and '_index' $page->setName('_index' . pathinfo($path, PATHINFO_EXTENSION)); $page->setTitle($parent->getTitle()); } else { $page->setName($path); $page->setTitle($title); } return $page; }