<commit_before><?php namespace Todaymade\Daux\Format\HTML;

class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
{
    private $language;
    private $homepage;

    private function initialize()
    {
        $this->homepage = false;
        if ($this->title === 'index') {
            $minimum_parent_dir_size = ($this->params['multilanguage']) ? 2 : 1;
            if (count($this->file->getParents()) >= $minimum_parent_dir_size) {
                $this->title = $this->file->getParent()->getTitle();
            } else {
                $this->homepage = ($this->file->getName() === '_index');
                $this->title = $this->params['title'];
            }
        }

        $this->language = '';
        if ($this->params['multilanguage'] && count($this->file->getParents())) {
            $language_dir = $this->file->getParents()[0];
            $this->language = $language_dir->getName();
        }
    }

    /**
     * @param \Todaymade\Daux\Tree\Directory[] $parents
     * @param bool $multilanguage
     * @return array
     */
    private function getBreadcrumbTrail($parents, $multilanguage)
    {
        if ($multilanguage && !empty($parents)) {
            $parents = array_splice($parents, 1);
        }
        $breadcrumb_trail = array();
        if (!empty($parents)) {
            foreach ($parents as $node) {
                $breadcrumb_trail[$node->getTitle()] = $node->getUrl();
            }
        }
        return $breadcrumb_trail;
    }

    protected function generatePage()
    {
        $this->initialize();
        $params = $this->params;

        $entry_page = [];
        if ($params['request'] === $params['index_key']) {
            if ($params['multilanguage']) {
                foreach ($params['languages'] as $key => $name) {
                    $entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
                }
            } else {
                $entry_page['View Documentation'] = $params['base_page'] . $params['entry_page']->getUrl();
            }
        } elseif ($params['file_uri'] === 'index') {
            $entry_page[$params['entry_page']->getTitle()] = $params['base_page'] . $params['entry_page']->getUrl();
        }

        $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'],
            'content' => $this->convertPage($this->content),
            'breadcrumbs' => $params['breadcrumbs']
        ];

        if ($page['breadcrumbs']) {
            $page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params['multilanguage']);
            $page['breadcrumb_separator'] = $params['breadcrumb_separator'];
        }

        $template = new Template($params['templates'], $params['theme']['templates']);
        return $template->render($this->homepage ? 'home' : 'content', ['page' => $page, 'params' => $params]);<commit_msg>Fix and simplify homepage detection in HTML generator<commit_after><?php namespace Todaymade\Daux\Format\HTML;

use Todaymade\Daux\Daux;
use Todaymade\Daux\Tree\Root;

class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
{
    private $language;
    private $homepage;

    private function initialize()
    {
        $this->homepage = false;
        if ($this->file->getParent()->getIndexPage() == $this->file) {
            if ($this->params['multilanguage']) {
                if ($this->file->getParent()->getParent() instanceof Root) {
                    $this->homepage = true;
                }
            } elseif ($this->file->getParent() instanceof Root) {
                $this->homepage = true;
            }
        }

        $this->language = '';
        if ($this->params['multilanguage'] && count($this->file->getParents())) {
            $language_dir = $this->file->getParents()[0];
            $this->language = $language_dir->getName();
        }
    }

    /**
     * @param \Todaymade\Daux\Tree\Directory[] $parents
     * @param bool $multilanguage
     * @return array
     */
    private function getBreadcrumbTrail($parents, $multilanguage)
    {
        if ($multilanguage && !empty($parents)) {
            $parents = array_splice($parents, 1);
        }
        $breadcrumb_trail = array();
        if (!empty($parents)) {
            foreach ($parents as $node) {
                $breadcrumb_trail[$node->getTitle()] = $node->getUrl();
            }
        }
        return $breadcrumb_trail;
    }

    protected function generatePage()
    {
        $this->initialize();
        $params = $this->params;

        $entry_page = [];
        if ($this->homepage) {
            if ($params['multilanguage']) {
                foreach ($params['languages'] as $key => $name) {
                    $entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
                }
            } else {
                $entry_page['View Documentation'] = $params['base_page'] . $params['entry_page']->getUrl();
            }
        }

        $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'],
            'content' => $this->convertPage($this->content),
            'breadcrumbs' => $params['breadcrumbs']
        ];

        if ($page['breadcrumbs']) {
            $page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params['multilanguage']);
            $page['breadcrumb_separator'] = $params['breadcrumb_separator'];
        }

        $template = new Template($params['templates'], $params['theme']['templates']);
        return $template->render($this->homepage ? 'home' : 'content', ['page' => $page, 'params' => $params]);
{'fraction_non_alphanumeric': 0.18119013973936254, 'fraction_numerical': 0.0009420631182289214, 'mean_word_length': 2.1865932966483244, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 126, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4533309', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1822, 'n_words': 292}