Package: pelican-compressor
Pelican plugin forweb-compressorpelican-compressoptimizes any Pelican site'soutput- using sane defaults & insane tools.InstallationIt's available fromPyPiusing a package manager of your choice:# Using 'pip'
pip install pelican-compressor

# Using 'poetry'
poetry add pelican-compressorGetting startedUsingpelican-compressoris straightforward:PluginAfter installing it, the following features are enabled by default:minification of HTML files & web assets, such as CSS/JS, JSON & XML filescachebusting assets, such as CSS/JS, JSON & XML files, fonts and imagescreating SRI hashes forlink&scripttagsSee 'Configuration' below for full control over these processes and even more features, such asoptimizing all JPEG & PNG imagesconverting them to modern file formats such as AVIF/WebPbuilding CSP directives (including nonces for inline scripts & styles)CommandlineInstallingpelican-compressoralso gives you access towebcompr, which might be interesting for more flexibility.ConfigurationThe following settings need to be prepended byCOMPRESSOR_to work, eg for enabling AVIF/WebP generation, defineCOMPRESSOR_ENABLE_MODERN_FORMATS = Truein your settings(most likelypelicanconf.py).GeneralSettingTypeDefaultDescriptionBLOCK_LISTlist[]Filenames to be excludedAsset minificationSettingTypeDefaultDescriptionENABLE_MINIFYbooltrueEnables/disables featureMINIFY_MEDIATYPESlistorre.PatternHTML, CSS, JS, SVGFiles to be minifiedMINIFY_OPTIONSdictsee belowMinification settingsFor available minification settings, seehere.Image optimizationsSettingTypeDefaultDescriptionENABLE_IMAGEOPTIMboolfalseEnables/disables featureIMAGEOPTIM_MEDIATYPESlistorre.PatternJPG/PNGFiles to be optimizedJPEG_QUALITYint85JPEG output qualitySTRIP_METADATAbooltrueWhether to remove metadataAsset hashing / "cachebusting"SettingTypeDefaultDescriptionENABLE_HASHINGbooltrueEnables/disables featureHASHING_MEDIATYPESlistorre.PatternCSS/JS files, fonts & imagesFiles to be hashedHASH_LENGTHint10Length of appended hash stringHASH_MODIFIEDboolfalseHash modified time or file contentsAVIF / WebP generationSettingTypeDefaultDescriptionENABLE_MODERN_FORMATSboolfalseEnables/disables featureAVIF_SETTINGSdict{"quality": 90}AVIF settings (see below)WEBP_SETTINGSdict{"method": 6}WebP settings (see below)Available WebP settings:losslessqualitymethodicc_profileexifFor more information, seePillowdocs.Available AVIF settings:advancedalpha_premultipliedappend_imagescodecdurationexificc_profileqmaxqminqualityrangespeedsubsamplingtile_rowsxmp/XML:com.adobe.xmpNote: AVIF generation is provided through a plugin, whichhasn't made it intoPillow's core yet, so consider this feature as being experimental!For more information (eg default values), check out theinfo.get()calls inside the_save()method, courtesy of thepillow_avifplugin.Subresource integritySettingTypeDefaultDescriptionENABLE_SRIstrtrueEnables/disables featureSRI_DIGESTstr'sha512'Cryptographic digest to useContent security policySettingTypeDefaultDescriptionENABLE_CSPboolfalseEnables/disables featureCSP_DIGESTstr'sha512'Cryptographic digest to useCSP_NONCEstruuid.uuid4().hexRandom nonce to be usedCSP_DIRECTIVESdict{}CSP directives (see below)When creating acontent security policy, you might want to start with something restrictive and go from there:COMPRESSOR_ENABLE_CSP=TrueCOMPRESSOR_CSP_DIRECTIVES={"default-src":"none","script-src":"'strict-dynamic'","object-src":"none","base-uri":"none",},HooksIt's also prossible to assign functions to be called right before this plugin (PRE_HOOK) or immediately thereafter (POST_HOOK), eg for creating image variants (such as placeholders for lazyloading). Each function receives the argumentasset, which is a tuple consisting of thepathlib.Pathto each asset file and astrrepresenting its MIME type:# pelicanconf.pyCOMPRESSOR_PRE_HOOK=lambdaasset:(# Unpack asset file & mediatypefile_path,mime_type=asset# If image file ..ifmime_type=="image/jpeg":# .. do something)RoadmapUpdateREADME.mdAdd tests