Skip to content

Commit b883d89

Browse files
authored
Merge pull request #3 from dkrnl/master
Add 'html_compress_exclude_pattern' config var
2 parents 7f5a8ad + 0201b81 commit b883d89

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ParamonovavSpressHtmlCompress.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class ParamonovavSpressHtmlCompress implements PluginInterface
1111
/** @var IOInterface */
1212
private $io;
1313

14+
15+
private $html_compress_exclude_pattern = '/(.*)?\.(jpe?g|png|gif|ico|svg|psd|tiff|webm|mov|avi|mkv|mp4)$/i';
16+
1417
/** @var string[] */
1518
private $html_compress_exclude = ['.htaccess','robots.txt','crossdomain.xml', 'sitemap.xml', 'rss.xml'];
1619

@@ -20,6 +23,7 @@ class ParamonovavSpressHtmlCompress implements PluginInterface
2023
/**
2124
* @param EventSubscriber $subscriber
2225
*/
26+
2327
public function initialize(EventSubscriber $subscriber)
2428
{
2529
$subscriber->addEventListener('spress.start', 'onStart');
@@ -54,17 +58,23 @@ public function onStart(EnvironmentEvent $event)
5458
{
5559
$this->html_compress_exclude = $configValues['html_compress_exclude'];
5660
}
61+
62+
if(isset($configValues['html_compress_exclude_pattern']))
63+
{
64+
$this->html_compress_exclude_pattern = $configValues['html_compress_exclude_pattern'];
65+
}
66+
5767
}
5868

5969
/**
6070
* @param RenderEvent $event
6171
*/
6272
public function onAfterRenderPage(RenderEvent $event)
6373
{
64-
6574
$id = $event->getId();
6675

67-
if (!$this->htmlCompress || in_array($id, $this->html_compress_exclude, true) || preg_match('/(.*)?\.(jpe?g|png|gif|ico|svg|psd|tiff|webm|mov|avi|mkv|mp4)$/i', $id)) {
76+
if (!$this->htmlCompress || in_array($id, $this-> html_compress_exclude) || preg_match($this->html_compress_exclude_pattern, $id))
77+
{
6878
return;
6979
}
7080

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Add the following to your config.yml to exclude some files from minify/compress
2121

2222
```yaml
2323
html_compress_exclude: ['.htaccess','robots.txt','crossdomain.xml', 'sitemap.xml','nortonsw_bc7be3d0-796e-0.html','BingSiteAuth.xml']
24+
html_compress_exclude_pattern: '/(.*)?\.(jpe?g|png|gif|ico|svg|psd|tiff|webm|mov|avi|mkv|mp4|eot|ttf|otf|woff|woff2|webp)$/i'
2425
```
2526
2627
Just run build command:

0 commit comments

Comments
 (0)