/** * @param Directory $parent * @param string $path * @return ContentAbstract */ public static function getOrCreatePage(Directory $parent, $path) { $extension = pathinfo($path, PATHINFO_EXTENSION); // If the file doesn't have an extension, set .md as a default if ($extension == '') { $extension = 'md'; $path .= '.md'; } $raw = !in_array($extension, $parent->getConfig()['valid_content_extensions']); $title = $uri = $path; if (!$raw) { $title = static::getName($path); $uri = DauxHelper::slug($title); if ($parent->getConfig()->isStatic()) { $uri .= '.html'; } } if (array_key_exists($uri, $parent->getEntries())) { return $parent->getEntries()[$uri]; } $page = $raw ? new ComputedRaw($parent, $uri) : new Content($parent, $uri); $page->setContent('-'); //set an almost empty content to avoid problems $page->setName($path); $page->setTitle($title); if ($title == 'index' || $title == '_index') { $page->setTitle($parent->getTitle()); } return $page; }
/** * @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; }