1
0
Fork 0
forked from github/pelican
pelican-theme/pelican/contents.py
Alexander Artemenko 3afdb8fcff Articles translations are enabled. To use this feature, you need to
add a Lang meta into the each article and set DEFAULT_LANG setting
which is 'en' by default.

Than, only articles in the default language (or without variant in
default language) will be shown in the index of the blog. And each
Article will have translations list.

The same is applicable to the static Pages.

Also, separate feeds are generated for each language except default.
2010-12-20 22:02:27 +03:00

68 lines
1.9 KiB
Python

from pelican.utils import slugify, truncate_html_words
class Page(object):
"""Represents a page
Given a content, and metadatas, 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):
self.content = content
self.translations = []
self.status = "published" # default value
for key, value in metadatas.items():
setattr(self, key, value)
if not hasattr(self, 'author'):
if 'AUTHOR' in settings:
self.author = settings['AUTHOR']
default_lang = settings.get('DEFAULT_LANG', 'en').lower()
if not hasattr(self, 'lang'):
self.lang = default_lang
self.in_default_lang = (self.lang == default_lang)
if not hasattr(self, 'slug'):
self.slug = slugify(self.title)
if not hasattr(self, 'url'):
if self.in_default_lang:
self.url = '%s.html' % self.slug
else:
self.url = '%s-%s.html' % (self.slug, self.lang)
if filename:
self.filename = filename
def check_properties(self):
"""test that each mandatory property is set."""
for prop in self.mandatory_properties:
if not hasattr(self, prop):
raise NameError(prop)
@property
def summary(self):
return truncate_html_words(self.content, 50)
class Article(Page):
mandatory_properties = ('title', 'date', 'category')
class Quote(Page):
base_properties = ('author', 'date')
def is_valid_content(content, f):
try:
content.check_properties()
return True
except NameError as e:
print u" [info] Skipping %s: impossible to find informations about '%s'" % (f, e)
return False