protected function addId(Heading $node) { // If the node has an ID, no need to generate it $attributes = $node->getData('attributes', []); if (array_key_exists('id', $attributes) && !empty($attributes['id'])) { // TODO :: check for uniqueness return $attributes['id']; } // Well, seems we have to generate an ID $walker = $node->walker(); $inside = []; while ($event = $walker->next()) { $insideNode = $event->getNode(); if ($insideNode instanceof Heading) { continue; } $inside[] = $insideNode; } $text = ''; foreach ($inside as $other) { if ($other instanceof Text) { $text .= ' ' . $other->getContent(); } } $text = 'page_' . DauxHelper::slug(trim($text)); // TODO :: check for uniqueness $node->data['attributes']['id'] = $text; }
/** * @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; }