From 6b44d937809e3e014660b9e76b37bf0738723a9e Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sun, 8 May 2011 14:58:57 +0100 Subject: [PATCH] Add the possibility to publish drafts. Fixes #111 --- docs/getting_started.rst | 8 ++++++++ pelican/contents.py | 3 +++ pelican/generators.py | 19 +++++++++++++------ pelican/settings.py | 1 + samples/content/draft_article.rst | 7 +++++++ 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 samples/content/draft_article.rst diff --git a/docs/getting_started.rst b/docs/getting_started.rst index fc2e171e..823e0f97 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -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. diff --git a/pelican/contents.py b/pelican/contents.py index a3c6670b..dc05dae4 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -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 diff --git a/pelican/generators.py b/pelican/generators.py index 7657261b..2ba36dcb 100755 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -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) diff --git a/pelican/settings.py b/pelican/settings.py index a744f465..a63cec3f 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -39,6 +39,7 @@ _DEFAULT_CONFIG = {'PATH': None, 'DEFAULT_ORPHANS': 0, 'DEFAULT_METADATA': (), 'FILES_TO_COPY': (), + 'DEFAULT_STATUS': 'published', } def read_settings(filename): diff --git a/samples/content/draft_article.rst b/samples/content/draft_article.rst new file mode 100644 index 00000000..76ce9a16 --- /dev/null +++ b/samples/content/draft_article.rst @@ -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.