From 0ec0cf9d0e822f25eee92910689a2763c377d8c2 Mon Sep 17 00:00:00 2001 From: Dirk Makowski Date: Tue, 28 Aug 2012 00:38:17 +0200 Subject: [PATCH] Patch to allow relative ASSET_URL Previously, webassets' ASSET_URL always was absolute. This patch allows a relative ASSET_URL, depending on Pelican's RELATIVE_URLS setting. Hint for templates: ------------------- Current version of webassets seem 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/'. XXX However, this breaks the ASSET_URL if user navigates to a sub-URL, e.g. if he clicks on a category. To workaround this issue, I use instead of Maybe this hint is worth to be included in the documentation. I have it also written as comments in the source. --- pelican/generators.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pelican/generators.py b/pelican/generators.py index ae9334da..9876da3b 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -429,7 +429,23 @@ class StaticGenerator(Generator): # Define the assets environment that will be passed to the # generators. The StaticGenerator must then be run first to have # the assets in the output_path before generating the templates. - assets_url = self.settings['SITEURL'] + '/theme/' + + # Let ASSET_URL honor Pelican's RELATIVE_URLS setting. + # Hint for templates: + # Current version of webassets seem 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/'. + # XXX However, this breaks the ASSET_URL if user navigates to + # a sub-URL, e.g. if he clicks on a category. To workaround this + # issue, I use + # + # instead of + # + if self.settings.get('RELATIVE_URLS'): + assets_url = './theme/' + else: + assets_url = self.settings['SITEURL'] + '/theme/' assets_src = os.path.join(self.output_path, 'theme') self.assets_env = AssetsEnvironment(assets_src, assets_url)