mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Change webassets configuration for relative urls.
Set the ASSET_URL to be relative to the 'theme/' url, which requires to use
{{ SITEURL }}/{{ ASSET_URL }} in the template and make it works with both
relative and absolute urls.
This commit is contained in:
parent
67af48eed4
commit
f413a8da79
4 changed files with 17 additions and 25 deletions
|
|
@ -6,20 +6,11 @@ Asset management plugin for Pelican
|
|||
This plugin allows you to use the `webassets`_ module to manage assets such as
|
||||
CSS and JS files.
|
||||
|
||||
Hint for templates: Current version of webassets seems to remove any relative
|
||||
paths at the beginning of the URL. So, if ``RELATIVE_URLS`` is on,
|
||||
``ASSET_URL`` will start with ``theme/``, regardless if we set ``assets_url``
|
||||
here to ``./theme/`` or to ``theme/``.
|
||||
|
||||
However, this breaks the ``ASSET_URL`` if user navigates to a sub-URL, e.g. if
|
||||
he clicks on a category. A workaround for this issue is to use::
|
||||
The ASSET_URL is set to a relative url to honor Pelican's RELATIVE_URLS
|
||||
setting. This requires the use of SITEURL in the templates::
|
||||
|
||||
<link rel="stylesheet" href="{{ SITEURL }}/{{ ASSET_URL }}">
|
||||
|
||||
instead of::
|
||||
|
||||
<link rel="stylesheet" href="{{ ASSET_URL }}">
|
||||
|
||||
.. _webassets: https://webassets.readthedocs.org/
|
||||
|
||||
"""
|
||||
|
|
@ -41,17 +32,11 @@ def add_jinja2_ext(pelican):
|
|||
def create_assets_env(generator):
|
||||
"""Define the assets environment and pass it to the generator."""
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Let ASSET_URL honor Pelican's RELATIVE_URLS setting.
|
||||
if generator.settings.get('RELATIVE_URLS'):
|
||||
assets_url = './theme/'
|
||||
else:
|
||||
assets_url = generator.settings['SITEURL'] + '/theme/'
|
||||
assets_url = 'theme/'
|
||||
assets_src = os.path.join(generator.output_path, 'theme')
|
||||
|
||||
generator.env.assets_environment = Environment(assets_src, assets_url)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
if logging.getLevelName(logger.getEffectiveLevel()) == "DEBUG":
|
||||
generator.env.assets_environment.debug = True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue