-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
54 lines (46 loc) · 1.37 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
@include_once __DIR__ . '/vendor/autoload.php';
use Kirby\Cms\App as Kirby;
use Kirby\Cms\Template;
use voku\helper\HtmlMin;
class MinifyHTML extends Template
{
/**
* @param array $data
* @return string
*/
public function render(array $data = []): string
{
$kirby = Kirby::instance();
$html = parent::render($data);
if (
$kirby->option('afbora.kirby-minify-html.enabled') === true &&
$this->hasDefaultType() === true
) {
$htmlMin = new HtmlMin();
$options = $kirby->option('afbora.kirby-minify-html.options', []);
foreach ($options as $option => $param) {
if (method_exists($htmlMin, $option) === true) {
if ($param !== null) {
$htmlMin->{$option}($param);
} else {
$htmlMin->{$option}();
}
}
}
return $htmlMin->minify($html);
}
return $html;
}
}
Kirby::plugin('afbora/kirby-minify-html', [
'options' => [
'enabled' => true,
'options' => []
],
'components' => [
'template' => function (Kirby $kirby, string $name, string $type = 'html', string $defaultType = 'html') {
return new MinifyHTML($name, $type, $defaultType);
}
]
]);