mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
utils: Add path_to_url() and generalize get_relative_path()
The old get_relative_path() implementation assumed os.sep == '/', which doesn't hold on MS Windows. The new implementation uses split_all() for a more general component count. I added path_to_url(), because the: '/'.join(split_all(path)) idiom was showing up in a number of cases, and it's easier to understand what's going on when that reads: path_to_url(path) This will fix a number of places where I think paths and URLs were conflated, and should improve MS Windows support.
This commit is contained in:
parent
b59da89e80
commit
ae4fc5a25e
5 changed files with 25 additions and 13 deletions
|
|
@ -17,7 +17,7 @@ from pelican import signals
|
|||
from pelican.settings import _DEFAULT_CONFIG
|
||||
from pelican.utils import (slugify, truncate_html_words, memoized, strftime,
|
||||
python_2_unicode_compatible, deprecated_attribute,
|
||||
split_all)
|
||||
path_to_url)
|
||||
|
||||
# Import these so that they're avalaible when you import from pelican.contents.
|
||||
from pelican.urlwrappers import (URLWrapper, Author, Category, Tag) # NOQA
|
||||
|
|
@ -139,7 +139,7 @@ class Content(object):
|
|||
metadata = copy.copy(self.metadata)
|
||||
path = self.metadata.get('path', self.get_relative_source_path())
|
||||
metadata.update({
|
||||
'path': '/'.join(split_all(path)),
|
||||
'path': path_to_url(path),
|
||||
'slug': getattr(self, 'slug', ''),
|
||||
'lang': getattr(self, 'lang', 'en'),
|
||||
'date': getattr(self, 'date', datetime.now()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue