mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
pelican/utils: Add split_all() and rework static URL generation
I think the conversion from native paths to URLs is best put off until
we are actually trying to generate the URL. The old handling
(introduced in 2692586, Fixes #645 - Making cross-content linking
windows compatible, 2012-12-19) converted the path at StaticContent
initialization, which left you with a bogus StaticContent.src.
Once we drop the 'static' subdirectory, we will be able to drop the
`dest` and `url` parts from the StaticGenerator.generate_context()
handling, which will leave things looking a good deal cleaner than
they do now.
This commit is contained in:
parent
49bf80ec39
commit
33c60a78cd
3 changed files with 32 additions and 6 deletions
|
|
@ -480,3 +480,24 @@ def mkdir_p(path):
|
|||
except OSError as e:
|
||||
if e.errno != errno.EEXIST or not os.path.isdir(path):
|
||||
raise
|
||||
|
||||
|
||||
def split_all(path):
|
||||
"""Split a path into a list of components
|
||||
|
||||
While os.path.split() splits a single component off the back of
|
||||
`path`, this function splits all components:
|
||||
|
||||
>>> split_all(os.path.join('a', 'b', 'c'))
|
||||
['a', 'b', 'c']
|
||||
"""
|
||||
components = []
|
||||
while path:
|
||||
head,tail = os.path.split(path)
|
||||
if tail:
|
||||
components.insert(0, tail)
|
||||
elif head == path:
|
||||
components.insert(0, head)
|
||||
break
|
||||
path = head
|
||||
return components
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue