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 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 manually launching it each time you need. Use the `-r` option, or
`--autoreload`. `--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'): if not hasattr(self, 'summary'):
self.summary = property(lambda self: truncate_html_words(self.content, 50)).__get__(self, Page) 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. # store the settings ref.
self._settings = settings self._settings = settings

View file

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

View file

@ -39,6 +39,7 @@ _DEFAULT_CONFIG = {'PATH': None,
'DEFAULT_ORPHANS': 0, 'DEFAULT_ORPHANS': 0,
'DEFAULT_METADATA': (), 'DEFAULT_METADATA': (),
'FILES_TO_COPY': (), 'FILES_TO_COPY': (),
'DEFAULT_STATUS': 'published',
} }
def read_settings(filename): 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.