mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
parent
58e817cb0f
commit
652eb3686f
6 changed files with 46 additions and 16 deletions
|
|
@ -237,12 +237,18 @@ posts for the month at ``posts/2011/Aug/index.html``.
|
|||
==================================================== =====================================================
|
||||
Setting name (default value) What does it do?
|
||||
==================================================== =====================================================
|
||||
`ARTICLE_URL` (``'{slug}.html'``) The URL to refer to an ARTICLE.
|
||||
`ARTICLE_URL` (``'{slug}.html'``) The URL to refer to an article.
|
||||
`ARTICLE_SAVE_AS` (``'{slug}.html'``) The place where we will save an article.
|
||||
`ARTICLE_LANG_URL` (``'{slug}-{lang}.html'``) The URL to refer to an ARTICLE which doesn't use the
|
||||
`ARTICLE_LANG_URL` (``'{slug}-{lang}.html'``) The URL to refer to an article which doesn't use the
|
||||
default language.
|
||||
`ARTICLE_LANG_SAVE_AS` (``'{slug}-{lang}.html'``) The place where we will save an article which
|
||||
doesn't use the default language.
|
||||
`DRAFT_URL` (``'drafts/{slug}.html'``) The URL to refer to an article draft.
|
||||
`DRAFT_SAVE_AS` (``'drafts/{slug}.html'``) The place where we will save an article draft.
|
||||
`DRAFT_LANG_URL` (``'drafts/{slug}-{lang}.html'``) The URL to refer to an article draft which doesn't
|
||||
use the default language.
|
||||
`DRAFT_LANG_SAVE_AS` (``'drafts/{slug}-{lang}.html'``) The place where we will save an article draft which
|
||||
doesn't use the default language.
|
||||
`PAGE_URL` (``'pages/{slug}.html'``) The URL we will use to link to a page.
|
||||
`PAGE_SAVE_AS` (``'pages/{slug}.html'``) The location we will save the page. This value has to be
|
||||
the same as PAGE_URL or you need to use a rewrite in
|
||||
|
|
|
|||
|
|
@ -114,9 +114,10 @@ class Pelican(object):
|
|||
structure = re.sub('^/', '', structure)
|
||||
|
||||
for setting in ('ARTICLE_URL', 'ARTICLE_LANG_URL', 'PAGE_URL',
|
||||
'PAGE_LANG_URL', 'ARTICLE_SAVE_AS',
|
||||
'ARTICLE_LANG_SAVE_AS', 'PAGE_SAVE_AS',
|
||||
'PAGE_LANG_SAVE_AS'):
|
||||
'PAGE_LANG_URL', 'DRAFT_URL', 'DRAFT_LANG_URL',
|
||||
'ARTICLE_SAVE_AS', 'ARTICLE_LANG_SAVE_AS',
|
||||
'DRAFT_SAVE_AS', 'DRAFT_LANG_SAVE_AS',
|
||||
'PAGE_SAVE_AS', 'PAGE_LANG_SAVE_AS'):
|
||||
self.settings[setting] = os.path.join(structure,
|
||||
self.settings[setting])
|
||||
logger.warning("%s = '%s'" % (setting, self.settings[setting]))
|
||||
|
|
@ -174,8 +175,11 @@ class Pelican(object):
|
|||
pages_generator = next(g for g in generators
|
||||
if isinstance(g, PagesGenerator))
|
||||
|
||||
print('Done: Processed {} articles and {} pages in {:.2f} seconds.'.format(
|
||||
print('Done: Processed {} article(s), {} draft(s) and {} page(s) in ' \
|
||||
'{:.2f} seconds.'.format(
|
||||
len(articles_generator.articles) + len(articles_generator.translations),
|
||||
len(articles_generator.drafts) + \
|
||||
len(articles_generator.drafts_translations),
|
||||
len(pages_generator.pages) + len(pages_generator.translations),
|
||||
time.time() - start_time))
|
||||
|
||||
|
|
|
|||
|
|
@ -328,6 +328,11 @@ class Article(Page):
|
|||
default_template = 'article'
|
||||
|
||||
|
||||
class Draft(Page):
|
||||
mandatory_properties = ('title', 'category')
|
||||
default_template = 'article'
|
||||
|
||||
|
||||
class Quote(Page):
|
||||
base_properties = ('author', 'date')
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from operator import attrgetter, itemgetter
|
|||
from jinja2 import (Environment, FileSystemLoader, PrefixLoader, ChoiceLoader,
|
||||
BaseLoader, TemplateNotFound)
|
||||
|
||||
from pelican.contents import Article, Page, Static, is_valid_content
|
||||
from pelican.contents import Article, Draft, Page, Static, is_valid_content
|
||||
from pelican.readers import Readers
|
||||
from pelican.utils import copy, process_translations, mkdir_p, DateFormatter
|
||||
from pelican import signals
|
||||
|
|
@ -190,7 +190,8 @@ class ArticlesGenerator(Generator):
|
|||
self.categories = defaultdict(list)
|
||||
self.related_posts = []
|
||||
self.authors = defaultdict(list)
|
||||
self.drafts = []
|
||||
self.drafts = [] # only drafts in default language
|
||||
self.drafts_translations = []
|
||||
super(ArticlesGenerator, self).__init__(*args, **kwargs)
|
||||
signals.article_generator_init.send(self)
|
||||
|
||||
|
|
@ -376,11 +377,11 @@ class ArticlesGenerator(Generator):
|
|||
|
||||
def generate_drafts(self, write):
|
||||
"""Generate drafts pages."""
|
||||
for article in self.drafts:
|
||||
write(os.path.join('drafts', '%s.html' % article.slug),
|
||||
self.get_template(article.template), self.context,
|
||||
article=article, category=article.category,
|
||||
all_articles=self.articles)
|
||||
for draft in chain(self.drafts_translations, self.drafts):
|
||||
write(draft.save_as, self.get_template(draft.template),
|
||||
self.context, article=draft, category=draft.category,
|
||||
override_output=hasattr(draft, 'override_save_as'),
|
||||
all_articles=self.articles)
|
||||
|
||||
def generate_pages(self, writer):
|
||||
"""Generate the pages on the disk"""
|
||||
|
|
@ -403,6 +404,7 @@ class ArticlesGenerator(Generator):
|
|||
"""Add the articles into the shared context"""
|
||||
|
||||
all_articles = []
|
||||
all_drafts = []
|
||||
for f in self.get_files(
|
||||
self.settings['ARTICLE_DIR'],
|
||||
exclude=self.settings['ARTICLE_EXCLUDES']):
|
||||
|
|
@ -426,13 +428,22 @@ class ArticlesGenerator(Generator):
|
|||
if article.status.lower() == "published":
|
||||
all_articles.append(article)
|
||||
elif article.status.lower() == "draft":
|
||||
self.drafts.append(article)
|
||||
draft = self.readers.read_file(
|
||||
base_path=self.path, path=f, content_class=Draft,
|
||||
context=self.context,
|
||||
preread_signal=signals.article_generator_preread,
|
||||
preread_sender=self,
|
||||
context_signal=signals.article_generator_context,
|
||||
context_sender=self)
|
||||
all_drafts.append(draft)
|
||||
else:
|
||||
logger.warning("Unknown status %s for file %s, skipping it." %
|
||||
(repr(article.status),
|
||||
repr(f)))
|
||||
|
||||
self.articles, self.translations = process_translations(all_articles)
|
||||
self.drafts, self.drafts_translations = \
|
||||
process_translations(all_drafts)
|
||||
|
||||
signals.article_generator_pretaxonomy.send(self)
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ DEFAULT_CONFIG = {
|
|||
'ARTICLE_SAVE_AS': '{slug}.html',
|
||||
'ARTICLE_LANG_URL': '{slug}-{lang}.html',
|
||||
'ARTICLE_LANG_SAVE_AS': '{slug}-{lang}.html',
|
||||
'DRAFT_URL': 'drafts/{slug}.html',
|
||||
'DRAFT_SAVE_AS': os.path.join('drafts', '{slug}.html'),
|
||||
'DRAFT_LANG_URL': 'drafts/{slug}-{lang}.html',
|
||||
'DRAFT_LANG_SAVE_AS': os.path.join('drafts', '{slug}-{lang}.html'),
|
||||
'PAGE_URL': 'pages/{slug}.html',
|
||||
'PAGE_SAVE_AS': os.path.join('pages', '{slug}.html'),
|
||||
'PAGE_LANG_URL': 'pages/{slug}-{lang}.html',
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
<article>
|
||||
<header>
|
||||
<h1 class="entry-title">
|
||||
<a href="../a-draft-article.html" rel="bookmark"
|
||||
<a href="../drafts/a-draft-article.html" rel="bookmark"
|
||||
title="Permalink to A draft article">A draft article</a></h1>
|
||||
</header>
|
||||
|
||||
|
|
@ -97,4 +97,4 @@ listed anywhere else.</p>
|
|||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue