Skip to content

Commit bffcb53

Browse files
committed
Initial version
1 parent 5466411 commit bffcb53

File tree

19 files changed

+1143
-0
lines changed

19 files changed

+1143
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Ahmet Bora
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "afbora/kirby-minify-html",
3+
"description": "Enable minify HTML output for Kirby 3",
4+
"keywords": [
5+
"kirby",
6+
"kirby-3",
7+
"kirby-cms",
8+
"kirby3-plugin",
9+
"kirby-plugin"
10+
],
11+
"version": "1.0",
12+
"type": "kirby-plugin",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Ahmet Bora",
17+
"email": "[email protected]"
18+
}
19+
],
20+
"require": {
21+
"php": "^7.1.3",
22+
"getkirby/composer-installer": "^1.1.4"
23+
},
24+
"config": {
25+
"optimize-autoloader": true,
26+
"preferred-install": "dist",
27+
"sort-packages": true
28+
},
29+
"minimum-stability": "dev",
30+
"prefer-stable": true
31+
}

index.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
@include_once __DIR__ . '/vendor/autoload.php';
4+
5+
use Kirby\Toolkit\Tpl;
6+
use Kirby\Cms\Template;
7+
use Kirby\Cms\App as Kirby;
8+
9+
class MinifyHTML extends Template
10+
{
11+
public function render(array $data = []): string
12+
{
13+
$html = Tpl::load($this->file(), $data);
14+
15+
$search = array(
16+
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
17+
'/[^\S ]+\</s', // strip whitespaces before tags, except space
18+
'/(\s)+/s', // shorten multiple whitespace sequences
19+
'/<!--(.|\s)*?-->/' // Remove HTML comments
20+
);
21+
22+
$replace = array(
23+
'>',
24+
'<',
25+
'\\1',
26+
''
27+
);
28+
29+
$html = preg_replace($search, $replace, $html);
30+
31+
return $html;
32+
}
33+
}
34+
35+
Kirby::plugin('afbora/kirby-minify-html', [
36+
'components' => [
37+
'template' => function (Kirby $kirby, string $name, string $contentType = null) {
38+
return new MinifyHTML($name, $contentType);
39+
}
40+
]
41+
]);

vendor/autoload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer/autoload_real.php';
6+
7+
return ComposerAutoloaderInitb347d04a24e66ed035d9a7739784b824::getLoader();

0 commit comments

Comments
 (0)