• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 17771165489

16 Sep 2025 03:37PM UTC coverage: 81.785% (+0.03%) from 81.757%
17771165489

push

github

ArnaudLigny
refactor: better handle of image convertion

7 of 12 new or added lines in 2 files covered. (58.33%)

17 existing lines in 4 files now uncovered.

3161 of 3865 relevant lines covered (81.79%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.1
/src/Generator/Homepage.php
1
<?php
2

3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <arnaud@ligny.fr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Cecil\Generator;
15

16
use Cecil\Collection\Page\Page;
17
use Cecil\Collection\Page\Type;
18

19
/**
20
 * Homepage generator class.
21
 *
22
 * This class generates the homepage for each language defined in the configuration.
23
 * It creates a new index page for each language, collects all pages of that language,
24
 * sorts them, and sets the necessary variables for the homepage.
25
 * It also handles the case where the homepage already exists by cloning it.
26
 * Additionally, it sets the default "main" menu and adds an alias redirection
27
 * from the root directory if the language prefix is enabled for the default language.
28
 */
29
class Homepage extends AbstractGenerator implements GeneratorInterface
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function generate(): void
35
    {
36
        foreach ($this->config->getLanguages() as $lang) {
1✔
37
            $language = $lang['code'];
1✔
38
            $pageId = 'index';
1✔
39
            if ($language != $this->config->getLanguageDefault()) {
1✔
40
                $pageId = "$language/$pageId";
1✔
41
            }
42
            // creates a new index page...
43
            $page = (new Page($pageId))->setPath('')->setVariable('title', 'Home');
1✔
44
            // ... clones it if already exists
45
            if ($this->builder->getPages()->has($pageId)) {
1✔
46
                $page = clone $this->builder->getPages()->get($pageId);
1✔
47
            }
48
            /** @var \Cecil\Collection\Page\Page $page */
49
            $page->setType(Type::HOMEPAGE->value);
1✔
50
            // collects all pages
51
            $pages = $this->builder->getPages()->filter(function (Page $page) use ($language) {
1✔
52
                return $page->getType() == Type::PAGE->value
1✔
53
                    && $page->getVariable('published') === true
1✔
54
                    && ($page->getVariable('excluded') !== true && $page->getVariable('exclude') !== true)
1✔
55
                    && $page->isVirtual() === false
1✔
56
                    && $page->getVariable('language') == $language;
1✔
57
            });
1✔
58
            // or collects pages from a specified section
59
            /** @var \Cecil\Collection\Page\Collection $pages */
60
            if ($page->hasVariable('pagesfrom') && $this->builder->getPages()->has((string) $page->getVariable('pagesfrom'))) {
1✔
UNCOV
61
                $pages = $this->builder->getPages()->get((string) $page->getVariable('pagesfrom'))->getPages();
×
62
            }
63
            if ($pages instanceof \Cecil\Collection\Page\Collection) {
1✔
64
                // sorts pages
65
                $sortBy = $page->getVariable('sortby') ?? $this->config->get('pages.sortby');
1✔
66
                $pages = $pages->sortBy($sortBy);
1✔
67
                $page->setPages($pages);
1✔
68
                if ($pages->first()) {
1✔
69
                    $page->setVariable('date', $pages->first()->getVariable('date'));
1✔
70
                }
71
            }
72
            // set default "main" menu
73
            if (!$page->getVariable('menu')) {
1✔
74
                $page->setVariable('menu', ['main' => ['weight' => 0]]);
1✔
75
            }
76
            // add an alias redirection from the root directory if language path prefix is enabled for the default language
77
            if ($language == $this->config->getLanguageDefault() && $this->config->isEnabled('language.prefix')) {
1✔
UNCOV
78
                $page->setVariable('alias', '../');
×
79
            }
80
            $this->generatedPages->add($page);
1✔
81
        }
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc