-
Notifications
You must be signed in to change notification settings - Fork 1
/
coming_soon.py
executable file
·65 lines (53 loc) · 2.67 KB
/
coming_soon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import copy
import os
from pelican import logger as pelican_logger
from pelican import signals
from pelican.contents import Article
from pelican.utils import process_translations, order_content
# KNOWN ISSUES
# Can mess up RSS Feed
# Does not delete static content linked with visible_drafts
def _reprocess(article_generator):
pelican_logger.debug("-- Regenerating articles & their translations and fixing ordering")
origs, translations = process_translations(
article_generator.articles, translation_id=article_generator.settings["ARTICLE_TRANSLATION_ID"]
)
origs = order_content(origs, article_generator.settings["ARTICLE_ORDER_BY"])
article_generator.articles, article_generator.translations = origs, translations
def add_coming_soon(article_generator):
"""
Iterate through drafts and if they are marked as visible, add them to articles list.
"""
pelican_logger.debug("-- Adding drafts with visible_draft: true to articles list\n")
for _draft in article_generator.drafts:
draft = copy.deepcopy(_draft)
if hasattr(draft, "visible_draft") and draft.visible_draft.strip().lower() == "true":
if not draft.metadata:
draft.metadata = {}
draft.metadata["save_as"] = draft.save_as + ".delete"
soon_article = Article(content=u"This article will be published soon",
metadata=draft.metadata,
settings=draft.settings,
source_path=draft.source_path)
# Might be redundant
soon_article.author = draft.author
soon_article.slug = draft.slug
article_generator.articles.append(soon_article)
_reprocess(article_generator)
def delete_visible_drafts_content(article_generator, writer):
"""
Delete article output from drafts marked as visible_draft: true
"""
pelican_logger.debug("-- Deleting output from drafts marked as visible_draft: true so they can't be read\n")
for article in article_generator.articles:
if hasattr(article, 'visible_draft') and article.visible_draft.strip().lower() == "true":
path_to_delete = os.path.join(article_generator.settings.get('OUTPUT_PATH'), article.save_as)
pelican_logger.debug("Deleting " + path_to_delete)
if os.path.exists(path_to_delete):
os.remove(path_to_delete)
def register():
pelican_logger.debug("-" * 80)
pelican_logger.debug("Plugin: Coming Soon\n")
signals.article_generator_pretaxonomy.connect(add_coming_soon)
signals.article_writer_finalized.connect(delete_visible_drafts_content)
pelican_logger.debug("-" * 80)