mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Metadata, not metadatas.
This commit is contained in:
parent
56effc24cb
commit
52f2a8383a
4 changed files with 29 additions and 29 deletions
|
|
@ -49,14 +49,14 @@ Take a look to the Markdown reader::
|
|||
md = Markdown(extensions = ['meta', 'codehilite'])
|
||||
content = md.convert(text)
|
||||
|
||||
metadatas = {}
|
||||
metadata = {}
|
||||
for name, value in md.Meta.items():
|
||||
if name in _METADATAS_FIELDS:
|
||||
meta = _METADATAS_FIELDS[name](value[0])
|
||||
if name in _METADATA_FIELDS:
|
||||
meta = _METADATA_FIELDS[name](value[0])
|
||||
else:
|
||||
meta = value[0]
|
||||
metadatas[name.lower()] = meta
|
||||
return content, metadatas
|
||||
metadata[name.lower()] = meta
|
||||
return content, metadata
|
||||
|
||||
Simple isn't it ?
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,21 @@ from pelican.log import *
|
|||
|
||||
class Page(object):
|
||||
"""Represents a page
|
||||
Given a content, and metadatas, create an adequate object.
|
||||
Given a content, and metadata, create an adequate object.
|
||||
|
||||
:param string: the string to parse, containing the original content.
|
||||
:param markup: the markup language to use while parsing.
|
||||
"""
|
||||
mandatory_properties = ('title',)
|
||||
|
||||
def __init__(self, content, metadatas={}, settings={}, filename=None):
|
||||
def __init__(self, content, metadata={}, settings={}, filename=None):
|
||||
self._content = content
|
||||
self.translations = []
|
||||
|
||||
self.status = "published" # default value
|
||||
|
||||
local_metadata = dict(settings['DEFAULT_METADATA'])
|
||||
local_metadata.update(metadatas)
|
||||
local_metadata.update(metadata)
|
||||
for key, value in local_metadata.items():
|
||||
setattr(self, key.lower(), value)
|
||||
|
||||
|
|
|
|||
|
|
@ -183,10 +183,10 @@ class ArticlesGenerator(Generator):
|
|||
files = self.get_files(self.path, exclude=['pages',])
|
||||
all_articles = []
|
||||
for f in files:
|
||||
content, metadatas = read_file(f)
|
||||
content, metadata = read_file(f)
|
||||
|
||||
# if no category is set, use the name of the path as a category
|
||||
if 'category' not in metadatas.keys():
|
||||
if 'category' not in metadata.keys():
|
||||
|
||||
if os.path.dirname(f) == self.path:
|
||||
category = self.settings['DEFAULT_CATEGORY']
|
||||
|
|
@ -194,13 +194,13 @@ class ArticlesGenerator(Generator):
|
|||
category = os.path.basename(os.path.dirname(f))
|
||||
|
||||
if category != '':
|
||||
metadatas['category'] = unicode(category)
|
||||
metadata['category'] = unicode(category)
|
||||
|
||||
if 'date' not in metadatas.keys()\
|
||||
if 'date' not in metadata.keys()\
|
||||
and self.settings['FALLBACK_ON_FS_DATE']:
|
||||
metadatas['date'] = datetime.fromtimestamp(os.stat(f).st_ctime)
|
||||
metadata['date'] = datetime.fromtimestamp(os.stat(f).st_ctime)
|
||||
|
||||
article = Article(content, metadatas, settings=self.settings,
|
||||
article = Article(content, metadata, settings=self.settings,
|
||||
filename=f)
|
||||
if not is_valid_content(article, f):
|
||||
continue
|
||||
|
|
@ -273,8 +273,8 @@ class PagesGenerator(Generator):
|
|||
def generate_context(self):
|
||||
all_pages = []
|
||||
for f in self.get_files(os.sep.join((self.path, 'pages'))):
|
||||
content, metadatas = read_file(f)
|
||||
page = Page(content, metadatas, settings=self.settings,
|
||||
content, metadata = read_file(f)
|
||||
page = Page(content, metadata, settings=self.settings,
|
||||
filename=f)
|
||||
if not is_valid_content(page, f):
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import re
|
|||
from pelican.utils import get_date, open
|
||||
|
||||
|
||||
_METADATAS_PROCESSORS = {
|
||||
_METADATA_PROCESSORS = {
|
||||
'tags': lambda x: map(unicode.strip, x.split(',')),
|
||||
'date': lambda x: get_date(x),
|
||||
'status': unicode.strip,
|
||||
|
|
@ -30,11 +30,11 @@ class RstReader(Reader):
|
|||
extension = "rst"
|
||||
|
||||
def _parse_metadata(self, content):
|
||||
"""Return the dict containing metadatas"""
|
||||
"""Return the dict containing metadata"""
|
||||
output = {}
|
||||
for m in re.compile('^:([a-z]+): (.*)\s', re.M).finditer(content):
|
||||
name, value = m.group(1).lower(), m.group(2)
|
||||
output[name] = _METADATAS_PROCESSORS.get(
|
||||
output[name] = _METADATA_PROCESSORS.get(
|
||||
name, lambda x:x
|
||||
)(value)
|
||||
return output
|
||||
|
|
@ -42,7 +42,7 @@ class RstReader(Reader):
|
|||
def read(self, filename):
|
||||
"""Parse restructured text"""
|
||||
text = open(filename)
|
||||
metadatas = self._parse_metadata(text)
|
||||
metadata = self._parse_metadata(text)
|
||||
extra_params = {'input_encoding': 'unicode',
|
||||
'initial_header_level': '2'}
|
||||
rendered_content = core.publish_parts(text,
|
||||
|
|
@ -51,9 +51,9 @@ class RstReader(Reader):
|
|||
settings_overrides=extra_params)
|
||||
title = rendered_content.get('title')
|
||||
content = rendered_content.get('body')
|
||||
if not metadatas.has_key('title'):
|
||||
metadatas['title'] = title
|
||||
return content, metadatas
|
||||
if not metadata.has_key('title'):
|
||||
metadata['title'] = title
|
||||
return content, metadata
|
||||
|
||||
class MarkdownReader(Reader):
|
||||
enabled = bool(Markdown)
|
||||
|
|
@ -65,13 +65,13 @@ class MarkdownReader(Reader):
|
|||
md = Markdown(extensions = ['meta', 'codehilite'])
|
||||
content = md.convert(text)
|
||||
|
||||
metadatas = {}
|
||||
metadata = {}
|
||||
for name, value in md.Meta.items():
|
||||
name = name.lower()
|
||||
metadatas[name] = _METADATAS_PROCESSORS.get(
|
||||
metadata[name] = _METADATA_PROCESSORS.get(
|
||||
name, lambda x:x
|
||||
)(value[0])
|
||||
return content, metadatas
|
||||
return content, metadata
|
||||
|
||||
|
||||
class HtmlReader(Reader):
|
||||
|
|
@ -81,13 +81,13 @@ class HtmlReader(Reader):
|
|||
def read(self, filename):
|
||||
"""Parse content and metadata of (x)HTML files"""
|
||||
content = open(filename)
|
||||
metadatas = {'title':'unnamed'}
|
||||
metadata = {'title':'unnamed'}
|
||||
for i in self._re.findall(content):
|
||||
key = i.split(':')[0][5:].strip()
|
||||
value = i.split(':')[-1][:-3].strip()
|
||||
metadatas[key.lower()] = value
|
||||
metadata[key.lower()] = value
|
||||
|
||||
return content, metadatas
|
||||
return content, metadata
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue