2015-05-18 14:26:29 +02:00
|
|
|
<?php namespace Todaymade\Daux\Format\HTML;
|
2015-04-21 17:11:43 +02:00
|
|
|
|
2015-05-18 14:26:29 +02:00
|
|
|
class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
|
2015-04-21 17:11:43 +02:00
|
|
|
{
|
|
|
|
private $language;
|
|
|
|
private $homepage;
|
|
|
|
|
2015-05-18 14:26:29 +02:00
|
|
|
private function initialize()
|
2015-04-23 00:32:30 +02:00
|
|
|
{
|
2015-04-27 11:57:44 +02:00
|
|
|
$this->homepage = false;
|
2015-04-21 17:11:43 +02:00
|
|
|
if ($this->title === 'index') {
|
2015-05-18 14:26:29 +02:00
|
|
|
$minimum_parent_dir_size = ($this->params['multilanguage']) ? 2 : 1;
|
|
|
|
if (count($this->file->getParents()) >= $minimum_parent_dir_size) {
|
2015-07-18 20:52:14 +02:00
|
|
|
$this->title = $this->file->getParent()->getTitle();
|
2015-04-23 00:32:30 +02:00
|
|
|
} else {
|
2015-04-27 11:57:44 +02:00
|
|
|
$this->homepage = ($this->file->getName() === '_index');
|
2015-05-18 14:26:29 +02:00
|
|
|
$this->title = $this->params['title'];
|
2015-04-23 00:32:30 +02:00
|
|
|
}
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
2015-04-26 18:24:22 +02:00
|
|
|
|
2015-04-21 17:11:43 +02:00
|
|
|
$this->language = '';
|
2015-05-18 14:26:29 +02:00
|
|
|
if ($this->params['multilanguage'] && count($this->file->getParents())) {
|
2015-07-18 21:23:02 +02:00
|
|
|
$language_dir = $this->file->getParents()[0];
|
|
|
|
$this->language = $language_dir->getName();
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-18 21:23:02 +02:00
|
|
|
/**
|
|
|
|
* @param \Todaymade\Daux\Tree\Directory[] $parents
|
|
|
|
* @param bool $multilanguage
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-04-27 11:57:44 +02:00
|
|
|
private function getBreadcrumbTrail($parents, $multilanguage)
|
2015-04-23 00:32:30 +02:00
|
|
|
{
|
|
|
|
if ($multilanguage && !empty($parents)) {
|
|
|
|
$parents = array_splice($parents, 1);
|
|
|
|
}
|
2015-04-21 17:11:43 +02:00
|
|
|
$breadcrumb_trail = array();
|
|
|
|
if (!empty($parents)) {
|
|
|
|
foreach ($parents as $node) {
|
2015-04-23 00:32:30 +02:00
|
|
|
$breadcrumb_trail[$node->getTitle()] = $node->getUrl();
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $breadcrumb_trail;
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:26:29 +02:00
|
|
|
protected function generatePage()
|
2015-04-23 00:32:30 +02:00
|
|
|
{
|
2015-05-18 14:26:29 +02:00
|
|
|
$this->initialize();
|
2015-04-21 17:11:43 +02:00
|
|
|
$params = $this->params;
|
2015-04-22 18:24:10 +02:00
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
$entry_page = [];
|
|
|
|
if ($params['request'] === $params['index_key']) {
|
|
|
|
if ($params['multilanguage']) {
|
|
|
|
foreach ($params['languages'] as $key => $name) {
|
2015-04-23 10:24:50 +02:00
|
|
|
$entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
|
2015-04-23 00:32:30 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-26 18:24:22 +02:00
|
|
|
$entry_page['View Documentation'] = $params['base_page'] . $params['entry_page']->getUrl();
|
2015-04-23 00:32:30 +02:00
|
|
|
}
|
|
|
|
} elseif ($params['file_uri'] === 'index') {
|
2015-07-16 11:08:16 +02:00
|
|
|
$entry_page[$params['entry_page']->getTitle()] = $params['base_page'] . $params['entry_page']->getUrl();
|
2015-04-23 00:32:30 +02:00
|
|
|
}
|
2015-04-21 17:11:43 +02:00
|
|
|
|
2015-04-27 11:57:44 +02:00
|
|
|
$page = [
|
|
|
|
'entry_page' => $entry_page,
|
|
|
|
'homepage' => $this->homepage,
|
|
|
|
'title' => $this->file->getTitle(),
|
|
|
|
'filename' => $this->file->getName(),
|
|
|
|
'language' => $this->language,
|
|
|
|
'path' => $this->file->getPath(),
|
|
|
|
'modified_time' => filemtime($this->file->getPath()),
|
|
|
|
'markdown' => $this->content,
|
|
|
|
'request' => $params['request'],
|
2015-05-22 14:48:09 +02:00
|
|
|
'content' => $this->convertPage($this->content),
|
2015-04-27 11:57:44 +02:00
|
|
|
'breadcrumbs' => $params['breadcrumbs']
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($page['breadcrumbs']) {
|
|
|
|
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params['multilanguage']);
|
2015-04-21 17:11:43 +02:00
|
|
|
$page['breadcrumb_separator'] = $params['breadcrumb_separator'];
|
|
|
|
}
|
2015-04-23 00:32:30 +02:00
|
|
|
|
2015-04-23 10:24:50 +02:00
|
|
|
$template = new Template($params['templates'], $params['theme']['templates']);
|
2015-07-17 23:38:06 +02:00
|
|
|
return $template->render($this->homepage ? 'home' : 'content', ['page' => $page, 'params' => $params]);
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
|
|
|
}
|