Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function generate(PageCollection $pageCollection, \Closure $messageCallback)
 {
     $generatedPages = new PageCollection();
     $sections = [];
     // collects sections
     /* @var $page Page */
     foreach ($pageCollection as $page) {
         if ($page->getSection() != '') {
             $sections[$page->getSection()][] = $page;
         }
     }
     // adds node pages to collection
     if (count($sections) > 0) {
         $menuWeight = 100;
         foreach ($sections as $section => $pages) {
             if (!$pageCollection->has($section . '/index')) {
                 usort($pages, 'PHPoole\\Util::sortByDate');
                 $page = (new Page())->setId(Page::urlize(sprintf('%s/index', $section)))->setPathname(Page::urlize(sprintf('%s', $section)))->setTitle(ucfirst($section))->setNodeType(NodeType::SECTION)->setVariable('pages', $pages)->setVariable('menu', ['main' => ['weight' => $menuWeight]]);
                 $generatedPages->add($page);
             }
             $menuWeight += 10;
         }
     }
     return $generatedPages;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function generate(PageCollection $pageCollection, \Closure $messageCallback)
 {
     $generatedPages = new PageCollection();
     if (!$pageCollection->has('index')) {
         $filteredPages = $pageCollection->filter(function (Page $page) {
             return $page->getNodeType() === null && $page->getSection() == $this->config->get('site.paginate.homepage.section') && !empty($page->getBody());
         });
         $pages = $filteredPages->sortByDate()->toArray();
         /* @var $page Page */
         $page = (new Page())->setId('index')->setNodeType(NodeType::HOMEPAGE)->setPathname(Page::urlize(''))->setTitle('Home')->setVariable('pages', $pages)->setVariable('menu', ['main' => ['weight' => 1]]);
         $generatedPages->add($page);
     }
     return $generatedPages;
 }
Esempio n. 3
0
 /**
  * Converts page content:
  * - Yaml frontmatter to PHP array
  * - Markdown body to HTML.
  *
  * @param Page   $page
  * @param string $format
  *
  * @return Page
  */
 public function convertPage(Page $page, $format = 'yaml')
 {
     // converts frontmatter
     try {
         $variables = Converter::convertFrontmatter($page->getFrontmatter(), $format);
     } catch (Exception $e) {
         $message = sprintf("> Unable to convert frontmatter of '%s': %s", $page->getId(), $e->getMessage());
         call_user_func_array($this->phpoole->getMessageCb(), ['CONVERT_PROGRESS', $message]);
         return false;
     }
     $page->setVariables($variables);
     // converts body
     $html = Converter::convertBody($page->getBody());
     $page->setHtml($html);
     return $page;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function generate(PageCollection $pageCollection, \Closure $messageCallback)
 {
     $generatedPages = new PageCollection();
     $filteredPages = $pageCollection->filter(function (Page $page) {
         return in_array($page->getNodeType(), [NodeType::HOMEPAGE, NodeType::SECTION]);
     });
     /* @var $page Page */
     foreach ($filteredPages as $page) {
         if ($this->config->get('site.paginate.disabled')) {
             return $generatedPages;
         }
         $paginateMax = intval($this->config->get('site.paginate.max'));
         $paginatePath = $this->config->get('site.paginate.path');
         $pages = $page->getVariable('pages');
         $path = $page->getPathname();
         // paginate
         if (count($pages) > $paginateMax) {
             $paginateCount = ceil(count($pages) / $paginateMax);
             for ($i = 0; $i < $paginateCount; $i++) {
                 $pagesInPagination = array_slice($pages, $i * $paginateMax, $paginateMax);
                 $alteredPage = clone $page;
                 // first page
                 if ($i == 0) {
                     $alteredPage->setId(Page::urlize(sprintf('%s/index', $path)))->setPathname(Page::urlize(sprintf('%s', $path)))->setVariable('aliases', [sprintf('%s/%s/%s', $path, $paginatePath, 1)]);
                 } else {
                     $alteredPage->setId(Page::urlize(sprintf('%s/%s/%s/index', $path, $paginatePath, $i + 1)))->setPathname(Page::urlize(sprintf('%s/%s/%s', $path, $paginatePath, $i + 1)))->unVariable('menu');
                 }
                 // pagination
                 $pagination = ['pages' => $pagesInPagination];
                 if ($i > 0) {
                     $pagination += ['prev' => Page::urlize(sprintf('%s/%s/%s', $path, $paginatePath, $i))];
                 }
                 if ($i < $paginateCount - 1) {
                     $pagination += ['next' => Page::urlize(sprintf('%s/%s/%s', $path, $paginatePath, $i + 2))];
                 }
                 $alteredPage->setVariable('pagination', $pagination);
                 $generatedPages->add($alteredPage);
             }
         }
     }
     return $generatedPages;
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function generate(PageCollection $pageCollection, \Closure $messageCallback)
 {
     $generatedPages = new PageCollection();
     /* @var $page Page */
     foreach ($pageCollection as $page) {
         $aliases = [];
         if ($page->hasVariable('aliases')) {
             $aliases = $page->getVariable('aliases');
         }
         if ($page->hasVariable('alias')) {
             $aliases[] = $page->getVariable('alias');
         }
         if (!empty($aliases)) {
             foreach ($aliases as $alias) {
                 /* @var $aliasPage Page */
                 $aliasPage = (new Page())->setId($alias . '/redirect')->setPathname(Page::urlize($alias))->setTitle($alias)->setLayout('redirect.html')->setVariable('destination', $page->getPermalink());
                 $generatedPages->add($aliasPage);
             }
         }
     }
     return $generatedPages;
 }
Esempio n. 6
0
 /**
  * Creates node pages.
  */
 protected function createNodePages()
 {
     /* @var $terms Vocabulary */
     foreach ($this->taxonomies as $plural => $terms) {
         if (count($terms) > 0) {
             /*
              * Creates $plural/$term pages (list of pages)
              * ex: /tags/tag-1/
              */
             /* @var $pages PageCollection */
             foreach ($terms as $term => $pages) {
                 if (!$this->pageCollection->has($term)) {
                     $pages = $pages->sortByDate()->toArray();
                     $page = (new Page())->setId(Page::urlize(sprintf('%s/%s/index', $plural, $term)))->setPathname(Page::urlize(sprintf('%s/%s', $plural, $term)))->setTitle(ucfirst($term))->setNodeType(NodeType::TAXONOMY)->setVariable('pages', $pages)->setVariable('singular', $this->config->get('site.taxonomies')[$plural])->setVariable('pagination', ['pages' => $pages]);
                     $this->generatedPages->add($page);
                 }
             }
             /*
              * Creates $plural pages (list of terms)
              * ex: /tags/
              */
             $page = (new Page())->setId(Page::urlize($plural))->setPathname(strtolower($plural))->setTitle($plural)->setNodeType(NodeType::TERMS)->setVariable('plural', $plural)->setVariable('singular', $this->config->get('site.taxonomies')[$plural])->setVariable('terms', $terms);
             // add page only if a template exist
             try {
                 $this->generatedPages->add($page);
             } catch (Exception $e) {
                 echo $e->getMessage() . "\n";
                 // do not add page
                 unset($page);
             }
         }
     }
 }