示例#1
0
 private function generateRecursive(Directory $tree, Config $params, $base_url = '')
 {
     $final = ['title' => $this->prefix . $tree->getTitle()];
     $params['base_url'] = $params['base_page'] = $base_url;
     $params['image'] = str_replace('<base_url>', $base_url, $params['image']);
     if ($base_url !== '') {
         $params['entry_page'] = $tree->getFirstPage();
     }
     foreach ($tree->getEntries() as $key => $node) {
         if ($node instanceof Directory) {
             $final['children'][$this->prefix . $node->getTitle()] = $this->generateRecursive($node, $params, '../' . $base_url);
         } elseif ($node instanceof Content) {
             $params['request'] = $node->getUrl();
             $contentType = $this->daux->getContentTypeHandler()->getType($node);
             $data = ['title' => $this->prefix . $node->getTitle(), 'file' => $node, 'page' => ContentPage::fromFile($node, $params, $contentType)];
             // As the page is lazily generated
             // We do it now to fail fast in case of problem
             $data['page']->getContent();
             if ($key == 'index.html') {
                 $final['title'] = $this->prefix . $tree->getTitle();
                 $final['file'] = $node;
                 $final['page'] = $data['page'];
             } else {
                 $final['children'][$data['title']] = $data;
             }
         }
     }
     return $final;
 }
示例#2
0
 /**
  * @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;
 }
示例#3
0
 /**
  * @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;
 }