Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilii Iakliushin <viakliushin@gitlab.com>2020-11-12 18:59:35 +0300
committerVasilii Iakliushin <viakliushin@gitlab.com>2020-11-12 18:59:35 +0300
commite0fe6342d6db2d32b87a625bb6749c9ee244a9fe (patch)
tree1b45e861e120376dbdb0499abffe1d3216daa6e4
parentcc8137e80c00b4dc3584a73b8e17d48e06e687e0 (diff)
Add Gzip filter to compress html pages
Contributes to https://gitlab.com/gitlab-org/gitlab-docs/-/issues/879
-rw-r--r--Rules5
-rw-r--r--lib/filters/gzip.rb13
-rw-r--r--lib/helpers/generic.rb4
3 files changed, 22 insertions, 0 deletions
diff --git a/Rules b/Rules
index 77998113..ccc5bf7c 100644
--- a/Rules
+++ b/Rules
@@ -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