Package: pelican-webassets
Web Assets: A Plugin for PelicanThisPelicanplugin allows you to use
thewebassetsmodule to perform a number
of useful asset management functions on your web site, such as:CSS minification (cssmin,yui_css, ...)CSS compiling (less,sass, ...)JS building (uglifyjs,yui_js,closure, ...)Some other interesting abilities ofwebassetsinclude:URL Expiry or
"cache-busting",
allowing you to set the cache headers for your assets long into the
future, saving bandwidth and reducing page load-timesaspritemapperfunction to
automatically combine multiple icons into one large image with corresponding
position slicesadataurifunction to minimize the number of HTTP requests by
replacingurl()references in your stylesheets with internal
in-linedata URIsFor the complete list of whatwebassetscan do, check out theincluded
filterssection in thewebassets
documentation.InstallationGetting started withwebassetscouldn't be easier thanks topip:python -m pip install pelican-webassetsFor more detailed plugin installation instructions, please refer to thePelican Plugin Documentation.💡Keep in Mind:Each function you use in your{% asset filters %}arguments (more on this later) will need to be installed
separately. For example, if you wanted to use thelibsassfilter, you
will need topip install libsass. You can evencreate a custom
filterif you wanted.UsageWith the plugin installed, include one or more{% assets %}tags
into your web site's templates to generate everything your web page will
need. For example, something like this in your template…{%assetsfilters="libsass,cssmin",output="css/style.min.css","css/style.scss"%}<linkrel="stylesheet"href="{{SITEURL}}/{{ASSET_URL}}">{%endassets%}… will tellwebassetsto uselibsassandcssminto compile and
minify thecss/style.scssfile in your theme, and save the compiled
stylesheet ascss/style.min.cssin the output of your finished
website, along with thelinkelement like this in your web page:<linkhref="{SITEURL}/{THEME_STATIC_DIR}/css/style.min.css?b3a7c807"rel="stylesheet">🌠The More You Know:TheASSET_URLvariable is the concatenation
of your PelicanTHEME_STATIC_DIRsetting, theoutputargument, and
the "cache-busting" variable we already talked about.JavaScript ExampleAs another example, we can use thewebassetsclosure_jsfunction to
combine, minify, and compress two files in your web site's theme,js/jQuery.jsandjs/widgets.js:{%assetsfilters="closure_js",output="js/packed.js","js/jQuery.js","js/widgets.js"%}<scriptsrc="{{SITEURL}}/{{ASSET_URL}}"></script>{%endassets%}The resulting output will be a singlescripttag and its
corresponding file in your web site's generated output:<scriptsrc="{SITEURL}/{THEME_STATIC_DIR}/js/packed.js?00703b9d"></script>ConfigurationBeing a very small wrapper around thewebassetsmodule, there are
only a few options that you may need.WEBASSETS_DEBUGBy default, if Pelican is in DEBUG mode (pelican -D ...), this
plugin will putwebassetsin DEBUG mode, to help you with
debugging. To override this behavior, setWEBASSETS_DEBUG = Falseto
always process files regardless of Pelican's DEBUG flag, orTrueto always forcewebassetsinto DEBUG mode.# put webassets into DEBUG mode if Pelican isWEBASSETS_DEBUG=logger.getEffectiveLevel()<=logging.DEBUGWEBASSETS_CONFIGSomewebassetsfilters require extra configuration options to function
properly. You can useWEBASSETS_CONFIGto specify these options in a
list of(key, value)tuples that are passed along to thewebassetsenvironment.WEBASSETS_CONFIG=[("closure_compressor_optimization","ADVANCED_OPTIMIZATIONS"),("libsass_style","compressed")]WEBASSETS_BUNDLESBundlesare
a convenient way to group a collection of assets together along with
the information on how to properly process the files. TheWEBASSETS_BUNDLESoption allows us to make these Bundles by taking a
list of(name, args, kwargs)arguments that will be passed to thewebassetsenvironment.WEBASSETS_BUNDLES=(("my_bundle",("colors.scss","style.scss"),{"output': "style.min.css", "filters": ["libsass", "cssmin"]}),)Allowing you to simplify something like this in your web site's templates…{%assetsfilters="libsass,cssmin",output="style.min.css","colors.scss","style.scss"%}… into this:{%assets'my_bundle'%}WEBASSETS_SOURCE_PATHSIf your raw assets are in directories other than yourTHEME_STATIC_PATHS, you can supply additional directories to search
in withWEBASSETS_SOURCE_PATHS.WEBASSETS_SOURCE_PATHS=["stylehseets","javascript"]ContributingContributions are welcome and much appreciated. Every little bit
helps. You can contribute by improving the documentation, adding
missing features, and fixing bugs. You can also help out by reviewing
and commenting onexisting issues.To start contributing to this plugin, review theContributing to
Pelicandocumentation, beginning with theContributing Codesection.LicenseThis project is licensed under theAGPL-3.0
license