diff options
author | Vasilii Iakliushin <viakliushin@gitlab.com> | 2020-11-12 18:59:35 +0300 |
---|---|---|
committer | Vasilii Iakliushin <viakliushin@gitlab.com> | 2020-11-12 18:59:35 +0300 |
commit | e0fe6342d6db2d32b87a625bb6749c9ee244a9fe (patch) | |
tree | 1b45e861e120376dbdb0499abffe1d3216daa6e4 | |
parent | cc8137e80c00b4dc3584a73b8e17d48e06e687e0 (diff) |
Add Gzip filter to compress html pages
Contributes to https://gitlab.com/gitlab-org/gitlab-docs/-/issues/879
-rw-r--r-- | Rules | 5 | ||||
-rw-r--r-- | lib/filters/gzip.rb | 13 | ||||
-rw-r--r-- | lib/helpers/generic.rb | 4 |
3 files changed, 22 insertions, 0 deletions
@@ -100,6 +100,11 @@ compile '/**/*.md' do else layout "/#{item[:layout]}.*" end + + if Nanoc::Helpers::Generic.is_omnibus? + filter :gzip + write ext: 'html.gz' + end else layout '/redirect.*' end diff --git a/lib/filters/gzip.rb b/lib/filters/gzip.rb new file mode 100644 index 00000000..446c86b9 --- /dev/null +++ b/lib/filters/gzip.rb @@ -0,0 +1,13 @@ +class GzipFilter < Nanoc::Filter + identifier :gzip + + def run(content, params = {}) + output = StringIO.new + + gzip = Zlib::GzipWriter.new(output, Zlib::BEST_COMPRESSION) + gzip.write(content) + gzip.close + + output.string + end +end diff --git a/lib/helpers/generic.rb b/lib/helpers/generic.rb index 2bc27ea8..5e5ea01b 100644 --- a/lib/helpers/generic.rb +++ b/lib/helpers/generic.rb @@ -8,5 +8,9 @@ module Nanoc::Helpers def is_production? ENV['NANOC_ENV'] == 'production' end + + def is_omnibus? + ENV['NANOC_ENV'] == 'omnibus' + end end end |