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:
W. Trevor King 2013-03-06 10:06:42 -05:00 committed by Alexis Métaireau
commit 33c60a78cd
3 changed files with 32 additions and 6 deletions

View file

@ -25,6 +25,7 @@ from pelican.contents import (
from pelican.readers import read_file
from pelican.utils import copy, process_translations, mkdir_p
from pelican import signals
import pelican.utils
logger = logging.getLogger(__name__)
@ -518,13 +519,15 @@ class StaticGenerator(Generator):
for f in self.get_files(
os.path.join(self.path, static_path), extensions=False):
f_rel = os.path.relpath(f, self.path)
# On Windows, make sure we end up with Unix-like paths.
if os.name == 'nt':
f_rel = f_rel.replace('\\', '/')
# TODO remove this hardcoded 'static' subdirectory
dest = os.path.join('static', f_rel)
url = '/'.join(pelican.utils.split_all(dest))
sc = Static(
content=None,
metadata={'save_as': os.path.join('static', f_rel)},
metadata={
'save_as': dest,
'url': url,
},
settings=self.settings,
source_path=f_rel)
self.staticfiles.append(sc)