generators: Use the static format to read Static metadata

This cuts down on the remaining difference between static files and
articles/pages.  The main difference is that path-based metadata is
now parsed for static content.
This commit is contained in:
W. Trevor King 2013-01-04 16:12:34 -05:00
commit 29cdb37af3
2 changed files with 10 additions and 7 deletions

View file

@ -563,21 +563,24 @@ 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)
content, metadata = read_file(
f, fmt='static', settings=self.settings)
# TODO remove this hardcoded 'static' subdirectory
dest = os.path.join('static', f_rel)
url = pelican.utils.path_to_url(dest)
metadata['save_as'] = os.path.join('static', f_rel)
metadata['url'] = pelican.utils.path_to_url(metadata['save_as'])
sc = Static(
content=None,
metadata={
'save_as': dest,
'url': url,
},
metadata=metadata,
settings=self.settings,
source_path=f_rel)
self.staticfiles.append(sc)
self.add_source_path(sc)
# same thing for FILES_TO_COPY
for src, dest in self.settings['FILES_TO_COPY']:
content, metadata = read_file(
src, fmt='static', settings=self.settings)
metadata['save_as'] = dest
metadata['url'] = pelican.utils.path_to_url(metadata['save_as'])
sc = Static(
content=None,
metadata={'save_as': dest},

View file

@ -347,7 +347,7 @@ def read_file(path, fmt=None, settings=None):
metadata.update(reader_metadata)
# eventually filter the content with typogrify if asked so
if settings and settings.get('TYPOGRIFY'):
if content and settings and settings.get('TYPOGRIFY'):
from typogrify.filters import typogrify
content = typogrify(content)
metadata['title'] = typogrify(metadata['title'])