Add the possibility to publish drafts. Fixes #111

This commit is contained in:
Alexis Metaireau 2011-05-08 14:58:57 +01:00
commit 6b44d93780
5 changed files with 32 additions and 6 deletions

View file

@ -150,3 +150,11 @@ Autoreload
It's possible to tell pelican to watch for your modifications, instead of
manually launching it each time you need. Use the `-r` option, or
`--autoreload`.
Publishing drafts
-----------------
If you want to publish an article as a draft, for friends to review it for
instance, you can add a `status: draft` to its metadata, it will then be
available under the `drafts` folder, and not be listed under the index page nor
any category page.

View file

@ -62,6 +62,9 @@ class Page(object):
if not hasattr(self, 'summary'):
self.summary = property(lambda self: truncate_html_words(self.content, 50)).__get__(self, Page)
if not hasattr(self, 'status'):
self.status = settings['DEFAULT_STATUS']
# store the settings ref.
self._settings = settings

View file

@ -99,6 +99,7 @@ class ArticlesGenerator(Generator):
self.tags = defaultdict(list)
self.categories = defaultdict(list)
super(ArticlesGenerator, self).__init__(*args, **kwargs)
self.drafts = []
def generate_feeds(self, writer):
"""Generate the feeds from the current context, and output files."""
@ -140,8 +141,7 @@ class ArticlesGenerator(Generator):
def generate_pages(self, writer):
"""Generate the pages on the disk
TODO: change the name"""
"""Generate the pages on the disk"""
write = partial(
writer.write_file,
@ -181,6 +181,10 @@ class ArticlesGenerator(Generator):
paginated={'articles': articles, 'dates': dates},
page_name='category/%s' % cat)
for article in self.drafts:
write('drafts/%s.html' % article.slug, article_template, self.context,
article=article, category=article.category)
def generate_context(self):
"""change the context"""
@ -211,10 +215,13 @@ class ArticlesGenerator(Generator):
if not is_valid_content(article, f):
continue
if hasattr(article, 'tags'):
for tag in article.tags:
self.tags[tag].append(article)
all_articles.append(article)
if article.status == "published":
if hasattr(article, 'tags'):
for tag in article.tags:
self.tags[tag].append(article)
all_articles.append(article)
elif article.status == "draft":
self.drafts.append(article)
self.articles, self.translations = process_translations(all_articles)

View file

@ -39,6 +39,7 @@ _DEFAULT_CONFIG = {'PATH': None,
'DEFAULT_ORPHANS': 0,
'DEFAULT_METADATA': (),
'FILES_TO_COPY': (),
'DEFAULT_STATUS': 'published',
}
def read_settings(filename):

View file

@ -0,0 +1,7 @@
A draft article
###############
:status: draft
This is a draft article, it should live under the /drafts/ folder and not be
listed anywhere else.