mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #188 from jokull/master
Please review these updates I've made after some experience with Calepin
This commit is contained in:
commit
53f7811a89
4 changed files with 24 additions and 8 deletions
|
|
@ -2,6 +2,7 @@
|
|||
from pelican.utils import slugify, truncate_html_words
|
||||
from pelican.log import *
|
||||
from pelican.settings import _DEFAULT_CONFIG
|
||||
from datetime import datetime
|
||||
from os import getenv
|
||||
from sys import platform, stdin
|
||||
|
||||
|
|
@ -23,8 +24,6 @@ class Page(object):
|
|||
self._content = content
|
||||
self.translations = []
|
||||
|
||||
self.status = "published" # default value
|
||||
|
||||
local_metadata = dict(settings.get('DEFAULT_METADATA', ()))
|
||||
local_metadata.update(metadata)
|
||||
|
||||
|
|
@ -38,7 +37,7 @@ class Page(object):
|
|||
self.author = settings['AUTHOR']
|
||||
else:
|
||||
self.author = getenv('USER', 'John Doe')
|
||||
warning("Author of `{0}' unknow, assuming that his name is `{1}'".format(filename or self.title, self.author).decode("utf-8"))
|
||||
warning(u"Author of `{0}' unknow, assuming that his name is `{1}'".format(filename or self.title, self.author))
|
||||
|
||||
# manage languages
|
||||
self.in_default_lang = True
|
||||
|
|
@ -87,7 +86,10 @@ class Page(object):
|
|||
# manage status
|
||||
if not hasattr(self, 'status'):
|
||||
self.status = settings['DEFAULT_STATUS']
|
||||
|
||||
if not settings['WITH_FUTURE_DATES']:
|
||||
if hasattr(self, 'date') and self.date > datetime.now():
|
||||
self.status = 'draft'
|
||||
|
||||
# set summary
|
||||
if not hasattr(self, 'summary'):
|
||||
self.summary = truncate_html_words(self.content, 50)
|
||||
|
|
|
|||
|
|
@ -211,7 +211,12 @@ class ArticlesGenerator(Generator):
|
|||
files = self.get_files(self.path, exclude=['pages',])
|
||||
all_articles = []
|
||||
for f in files:
|
||||
content, metadata = read_file(f, settings=self.settings)
|
||||
|
||||
try:
|
||||
content, metadata = read_file(f, settings=self.settings)
|
||||
except Exception, e:
|
||||
warning(u'Could not process %s\n%s' % (f, str(e)))
|
||||
continue
|
||||
|
||||
# if no category is set, use the name of the path as a category
|
||||
if 'category' not in metadata.keys():
|
||||
|
|
@ -324,7 +329,11 @@ class PagesGenerator(Generator):
|
|||
def generate_context(self):
|
||||
all_pages = []
|
||||
for f in self.get_files(os.sep.join((self.path, 'pages'))):
|
||||
content, metadata = read_file(f)
|
||||
try:
|
||||
content, metadata = read_file(f)
|
||||
except Exception, e:
|
||||
error(u'Could not process %s\n%s' % (filename, str(e)))
|
||||
continue
|
||||
page = Page(content, metadata, settings=self.settings,
|
||||
filename=f)
|
||||
if not is_valid_content(page, f):
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ _DEFAULT_CONFIG = {'PATH': None,
|
|||
'PDF_GENERATOR': False,
|
||||
'DEFAULT_CATEGORY': 'misc',
|
||||
'FALLBACK_ON_FS_DATE': True,
|
||||
'WITH_FUTURE_DATES': True,
|
||||
'CSS_FILE': 'main.css',
|
||||
'REVERSE_ARCHIVE_ORDER': False,
|
||||
'REVERSE_CATEGORY_ORDER': False,
|
||||
|
|
|
|||
|
|
@ -17,8 +17,12 @@ def get_date(string):
|
|||
|
||||
If no format matches the given date, raise a ValuEerror
|
||||
"""
|
||||
formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M', '%Y-%m-%d', '%Y/%m/%d',
|
||||
'%d/%m/%Y', '%d.%m.%Y', '%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S']
|
||||
string = re.sub(' +', ' ', string)
|
||||
formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M',
|
||||
'%Y-%m-%d', '%Y/%m/%d',
|
||||
'%d-%m-%Y', '%Y-%d-%m', # Weird ones
|
||||
'%d/%m/%Y', '%d.%m.%Y',
|
||||
'%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S']
|
||||
for date_format in formats:
|
||||
try:
|
||||
return datetime.strptime(string, date_format)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue