-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 942ff72
Showing
7 changed files
with
827 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Python .gitignore, with .idea/ added. | ||
# https://github.com/github/gitignore/blob/master/Python.gitignore | ||
|
||
# PyCharm | ||
.idea/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019-2020 Kurt McKee <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
.. This file is part of the pelican_precompress plugin. | ||
.. Copyright 2019-2020 Kurt McKee <[email protected]> | ||
.. Released under the MIT license. | ||
pelican_precompress | ||
******************* | ||
|
||
*Pre-compress your Pelican site using gzip, zopfli, and brotli!* | ||
|
||
---- | ||
|
||
Are you using `Pelican`_, the static site generator? If so, great! | ||
Are you pre-compressing your static files to have the fastest site possible? | ||
If not, install **pelican_precompress** today! | ||
It's the plugin that makes your visitors happy and saves you money! | ||
|
||
|
||
Installation | ||
============ | ||
|
||
There are three steps required to start using static compression: | ||
|
||
#. Install the plugin and any supporting Python packages you want. | ||
#. Configure Pelican to use the pelican_precompress plugin. | ||
#. Configure your web server to use static, pre-compressed files. | ||
|
||
|
||
1. Install the Python modules | ||
----------------------------- | ||
|
||
At minimum, you'll need to install the pelican_precompress plugin. | ||
It will automatically generate gzip files because gzip is built into the | ||
Python standard library. | ||
|
||
However, if you want highly-optimized gzip files you'll need the zopfli module. | ||
And if you want to have the very best compression currently available, you'll | ||
need to install the brotli module (which will require extra work in step 3). | ||
|
||
.. code-block:: shell-session | ||
$ pip install pelican_precompress | ||
$ pip install zopfli # This produces smaller gzip'd files. Use it! | ||
$ pip install brotli # This requires extra work in step 3. | ||
Further reading: `zopfli`_, `brotli`_ | ||
|
||
|
||
2. Configure Pelican | ||
-------------------- | ||
|
||
You'll need to import the plugin and add it to the list of active plugins. | ||
Feel free to copy and paste the code below into your Pelican configuration file. | ||
Just uncomment and edit the configuration lines to your liking...or leave | ||
them alone because the defaults are awesome! | ||
|
||
.. code-block:: python3 | ||
import pelican_precompress | ||
PLUGINS = [pelican_precompress] | ||
# PRECOMPRESS_GZIP = True or False | ||
# PRECOMPRESS_ZOPFLI = True or False | ||
# PRECOMPRESS_BROTLI = True or False | ||
# PRECOMPRESS_OVERWRITE = False | ||
# PRECOMPRESS_TEXT_EXTENSIONS = { | ||
# '.atom', | ||
# '.css', | ||
# '.html', | ||
# '.but-the-default-extensions-are-pretty-comprehensive', | ||
# } | ||
Further reading: `Pelican plugins`_ | ||
|
||
|
||
3. Configure nginx | ||
------------------ | ||
|
||
nginx supports gzip compression right out of the box. | ||
To enable it, add something like this to your nginx configuration file: | ||
|
||
.. code-block:: nginx | ||
http { | ||
gzip_static on; | ||
gzip_vary on; | ||
} | ||
At the time of writing, nginx doesn't natively support brotli compression. | ||
To get it, you'll need to compile the static brotli module as an nginx | ||
dynamic module, or recompile nginx from scratch. When it's done you'll | ||
add something like this to your nginx configuration file: | ||
|
||
.. code-block:: nginx | ||
load_module /usr/lib/nginx/modules/ngx_http_brotli_static_module.so; | ||
http { | ||
brotli_static on; | ||
} | ||
Further reading: `gzip_static`_, `gzip_vary`_, `nginx brotli module`_ | ||
|
||
|
||
Configuration | ||
============= | ||
|
||
There are a small number of configuration options available. | ||
You set them in your Pelican configuration file. | ||
|
||
* ``PRECOMPRESS_GZIP`` (bool, default is True) | ||
|
||
This is always ``True`` unless you set this to ``False``. | ||
For example, you might turn this off during development. | ||
|
||
* ``PRECOMPRESS_ZOPFLI`` (bool, default is True if zopfli is installed) | ||
|
||
If the zopfli module is installed this will default to ``True``. | ||
You might set this to ``False`` during development. | ||
Note that if you try to enable zopfli compression but the module | ||
isn't installed then nothing will happen. | ||
|
||
* ``PRECOMPRESS_BROTLI`` (bool, default is True if brotli is installed) | ||
|
||
If the brotli module is installed this will default to ``True``. | ||
You might set this to ``False`` during development. | ||
Like ``PRECOMPRESS_ZOPFLI``, if you set this to ``True`` when the | ||
brotli module isn't installed then nothing will happen. | ||
|
||
* ``PRECOMPRESS_OVERWRITE`` (bool, default is False) | ||
|
||
When pelican_precompress encounters an existing compressed file | ||
it will refuse to overwrite it. If you want the plugin to overwrite | ||
files you can set this to ``True``. | ||
|
||
* ``PRECOMPRESS_TEXT_EXTENSIONS`` (Set[str]) | ||
|
||
This setting controls which file extensions will be pre-compressed. | ||
|
||
If you modify this setting in the Pelican configuration file it will | ||
completely replace the default extensions! | ||
|
||
|
||
Testing | ||
======= | ||
|
||
**pelican_precompress** has 100% test coverage. If you'd like to test the | ||
code yourself, clone the git repository and run these commands: | ||
|
||
.. code-block:: shell | ||
$ python3 -m venv venv | ||
$ source venv/bin/activate | ||
(venv) $ python -m pip install tox | ||
(venv) $ tox | ||
The test suite uses tox to setup multiple environments with varying | ||
dependencies using multiple Python interpreters; pytest allows the | ||
test suite to have parametrized tests; pyfakefs creates a fake | ||
filesystem that the tests can run against; and coverage keeps track | ||
of which lines of code (and which branches) have been run. | ||
|
||
Further reading: `tox`_, `venv`_, `pytest`_, `pyfakefs`_, `coverage`_ | ||
|
||
|
||
.. Links | ||
.. ===== | ||
.. _Pelican: https://getpelican.com/ | ||
.. _Pelican plugins: https://docs.getpelican.com/en/latest/plugins.html | ||
.. _zopfli: https://pypi.org/project/zopfli/ | ||
.. _brotli: https://pypi.org/project/Brotli/ | ||
.. _gzip_static: https://nginx.org/en/docs/http/ngx_http_gzip_static_module.html#gzip_static | ||
.. _gzip_vary: https://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_vary | ||
.. _nginx brotli module: https://github.com/google/ngx_brotli | ||
.. _tox: https://tox.readthedocs.io/en/latest/ | ||
.. _pytest: https://docs.pytest.org/en/latest/ | ||
.. _pyfakefs: https://jmcgeheeiv.github.io/pyfakefs/release/ | ||
.. _venv: https://docs.python.org/3/library/venv.html | ||
.. _coverage: https://coverage.readthedocs.io/en/latest/ |
Oops, something went wrong.