1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Cecil/Cecil package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Cecil\Generator; |
12
|
|
|
|
13
|
|
|
use Cecil\Collection\Page\Page; |
14
|
|
|
use Cecil\Collection\Page\Type; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Generator\Homepage. |
18
|
|
|
*/ |
19
|
|
|
class Homepage extends AbstractGenerator implements GeneratorInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function generate(): void |
25
|
|
|
{ |
26
|
|
|
$subPages = $this->builder->getPages()->filter(function (Page $page) { |
27
|
|
|
return $page->getType() == TYPE::PAGE |
28
|
|
|
&& $page->isVirtual() === false // excludes virtual pages |
29
|
|
|
&& $page->getVariable('exclude') !== true; |
30
|
|
|
}); |
31
|
|
|
/** @var \Cecil\Collection\Page\Collection $subPages */ |
32
|
|
|
$pages = $subPages->sortByDate(); |
33
|
|
|
|
34
|
|
|
// creates a new index page... |
35
|
|
|
$page = (new Page('index'))->setPath('')->setVariable('title', 'Home'); |
36
|
|
|
// ... clones it if already exists |
37
|
|
|
if ($this->builder->getPages()->has('index')) { |
38
|
|
|
$page = clone $this->builder->getPages()->get('index'); |
39
|
|
|
} |
40
|
|
|
/** @var \Cecil\Collection\Page\Page $page */ |
41
|
|
|
$page->setType(Type::HOMEPAGE) |
42
|
|
|
->setVariable('pages', $pages); |
43
|
|
|
if ($pages->first()) { |
44
|
|
|
$page->setVariable('date', $pages->first()->getVariable('date')); |
45
|
|
|
} |
46
|
|
|
// default menu |
47
|
|
|
if (!$page->getVariable('menu')) { |
48
|
|
|
$page->setVariable('menu', [ |
49
|
|
|
'main' => ['weight' => 0], |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
$this->generatedPages->add($page); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|