Skip to content

Commit

Permalink
Add disable compress per page in frontmatter
Browse files Browse the repository at this point in the history
Closes #108
  • Loading branch information
jnvsor committed May 9, 2024
1 parent 57e192e commit 389088d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
10 changes: 10 additions & 0 deletions site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ layout: compress

Now all your markup will be processed by the `compress` layout.

You can disable compression on a page-by-page basis with the `compress_html` frontmatter. For example:

```html
---
compress_html: false
---

This page will not be compressed
```

## Configuration

By default the layout replaces contiguous whitespace with a single whitespace character. Additional settings can be specified in the `compress_html` key inside the `_config.yml` file. The default configuration is:
Expand Down
2 changes: 1 addition & 1 deletion src/compress.liquid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% endcapture %}

{% if site.compress_html.ignore.envs contains jekyll.environment or site.compress_html.ignore.envs == "all" %}
{% if site.compress_html.ignore.envs contains jekyll.environment or site.compress_html.ignore.envs == "all" or page.compress_html == false %}
{{ content }}
{% else %}

Expand Down
15 changes: 15 additions & 0 deletions test/expected/disabled/disabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div>One <b>Two</b> Three</div> <div>Four</div>
<!-- One --><div>Two<!--Three--></div><!-- Four-->
<head>
<title>One</title>
</head>
<body>
<p>Two</p>
</body>

<pre>

</pre><pre>

</pre>

5 changes: 5 additions & 0 deletions test/expected/disabled/enabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>One <b>Two</b> Three</div><div>Four</div><div>Two</div><head><title>One</title><body><p>Two</p><pre>

</pre><pre>

</pre>
19 changes: 19 additions & 0 deletions test/source/disabled/disabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
layout: compress
compress_html: false
---

<div>One <b>Two</b> Three</div> <div>Four</div>
<!-- One --><div>Two<!--Three--></div><!-- Four-->
<head>
<title>One</title>
</head>
<body>
<p>Two</p>
</body>

<pre>

</pre><pre>

</pre>
19 changes: 19 additions & 0 deletions test/source/disabled/enabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
layout: compress
compress_html: true
---

<div>One <b>Two</b> Three</div> <div>Four</div>
<!-- One --><div>Two<!--Three--></div><!-- Four-->
<head>
<title>One</title>
</head>
<body>
<p>Two</p>
</body>

<pre>

</pre><pre>

</pre>
5 changes: 5 additions & 0 deletions test/test_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def test_all
assert_dir "all"
end

def test_disabled
jekyll_build ["_config.yml", "_config_all.yml"]
assert_dir "disabled"
end

def test_clippings
jekyll_build ["_config.yml", "_config_clippings.yml"]
assert_dir "clippings"
Expand Down

0 comments on commit 389088d

Please sign in to comment.