Skip to content

Commit

Permalink
Merge pull request getpelican#280 from justinmayer/siteurl
Browse files Browse the repository at this point in the history
Remove trailing slash from SITEURL if present. Fixes getpelican#275.
  • Loading branch information
almet committed Mar 23, 2012
2 parents 0ed6cf7 + 65b93db commit bd767a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 5 additions & 4 deletions docs/settings.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ Setting name (default value) What does it do?
`SITEURL` Base URL of your website. Not defined by default, `SITEURL` Base URL of your website. Not defined by default,
which means the base URL is assumed to be "/" with a which means the base URL is assumed to be "/" with a
root-relative URL structure. If `SITEURL` is specified root-relative URL structure. If `SITEURL` is specified
explicitly, URLs will be generated with an absolute explicitly, there should be no trailing slash at the end,
URL structure (including the domain). If you want to and URLs will be generated with an absolute URL structure
use relative URLs instead of root-relative or absolute (including the domain). If you want to use relative URLs
URLs, you should instead use the `RELATIVE_URL` setting. instead of root-relative or absolute URLs, you should
instead use the `RELATIVE_URL` setting.
`STATIC_PATHS` (``['images']``) The static paths you want to have accessible `STATIC_PATHS` (``['images']``) The static paths you want to have accessible
on the output path "static". By default, on the output path "static". By default,
Pelican will copy the 'images' folder to the Pelican will copy the 'images' folder to the
Expand Down
12 changes: 9 additions & 3 deletions pelican/settings.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -128,9 +128,15 @@ def configure_settings(settings, default_settings=None, filename=None):
else: else:
logger.warn("LOCALE option doesn't contain a correct value") logger.warn("LOCALE option doesn't contain a correct value")


# If SITEURL is defined but FEED_DOMAIN isn't, set FEED_DOMAIN = SITEURL if ('SITEURL' in settings):
if ('SITEURL' in settings) and (not 'FEED_DOMAIN' in settings): # If SITEURL has a trailing slash, remove it and provide a warning
settings['FEED_DOMAIN'] = settings['SITEURL'] siteurl = settings['SITEURL']
if (siteurl[len(siteurl) - 1:] == '/'):
settings['SITEURL'] = siteurl[:-1]
logger.warn("Removed extraneous trailing slash from SITEURL.")
# If SITEURL is defined but FEED_DOMAIN isn't, set FEED_DOMAIN = SITEURL
if not 'FEED_DOMAIN' in settings:
settings['FEED_DOMAIN'] = settings['SITEURL']


# Warn if feeds are generated with both SITEURL & FEED_DOMAIN undefined # Warn if feeds are generated with both SITEURL & FEED_DOMAIN undefined
if (('FEED' in settings) or ('FEED_RSS' in settings)) and (not 'FEED_DOMAIN' in settings): if (('FEED' in settings) or ('FEED_RSS' in settings)) and (not 'FEED_DOMAIN' in settings):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_settings.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def test_read_empty_settings(self):
def test_configure_settings(self): def test_configure_settings(self):
"""Manipulations to settings should be applied correctly.""" """Manipulations to settings should be applied correctly."""


# SITEURL should not have a trailing slash
settings = {'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': ''}
configure_settings(settings)
self.assertEqual(settings['SITEURL'], 'http://blog.notmyidea.org')

# FEED_DOMAIN, if undefined, should default to SITEURL # FEED_DOMAIN, if undefined, should default to SITEURL
settings = {'SITEURL': 'http://blog.notmyidea.org', 'LOCALE': ''} settings = {'SITEURL': 'http://blog.notmyidea.org', 'LOCALE': ''}
configure_settings(settings) configure_settings(settings)
Expand Down

0 comments on commit bd767a5

Please sign in to comment.