diff --git a/pelican/utils.py b/pelican/utils.py index 767dc117..79387357 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -133,8 +133,12 @@ def clean_output_dir(path): def get_relative_path(filename): - """Return the relative path to the given filename""" - return '../' * filename.count('/') + '.' + """Return the relative path from the given filename to the root path.""" + nslashes = filename.count('/') + if nslashes == 0: + return '.' + else: + return '/'.join(['..'] * nslashes) def truncate_html_words(s, num, end_text='...'): diff --git a/tests/test_utils.py b/tests/test_utils.py index 58118d4f..eda1388a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -51,9 +51,9 @@ class TestUtils(unittest.TestCase): def test_get_relative_path(self): - samples = (('/test/test', '../../.'), - ('/test/test/', '../../../.'), - ('/', '../.')) + samples = (('test/test.html', '..'), + ('test/test/test.html', '../..'), + ('test.html', '.')) for value, expected in samples: self.assertEquals(utils.get_relative_path(value), expected) diff --git a/tests/test_webassets.py b/tests/test_webassets.py index afe1674d..ceba7775 100644 --- a/tests/test_webassets.py +++ b/tests/test_webassets.py @@ -79,7 +79,7 @@ class TestWebAssetsRelativeURLS(TestWebAssets): self.check_link_tag(css_file, os.path.join(self.temp_path, f)) self.check_link_tag( - '.././theme/gen/style.{0}.min.css'.format(CSS_HASH), + '../theme/gen/style.{0}.min.css'.format(CSS_HASH), os.path.join(self.temp_path, 'category/yeah.html'))