Add ARTICLE_RESTRICT_TO_TAGS setting

This commit is contained in:
Andreas Kloeckner 2018-04-13 12:18:54 -05:00
commit b49a0500e0
2 changed files with 13 additions and 0 deletions

View file

@ -179,6 +179,12 @@ Basic settings
A list of directories to exclude when looking for articles in addition to
``PAGE_PATHS``.
.. data:: ARTICLE_RESTRICT_TO_TAGS = []
All articles that do not have all tags in this list will be excluded from
the output. This is useful, for example, for generating multiple versions
of a site with overlapping content--e.g. a professional and a personal one.
.. data:: OUTPUT_SOURCES = False
Set to True if you want to copy the articles and pages in their original

View file

@ -564,6 +564,9 @@ class ArticlesGenerator(CachingGenerator):
def generate_context(self):
"""Add the articles into the shared context"""
restrict_all_articles_to_tags = set(
self.settings.get("ARTICLES_RESTRICT_TO_TAGS", []))
all_articles = []
all_drafts = []
for f in self.get_files(
@ -592,6 +595,10 @@ class ArticlesGenerator(CachingGenerator):
self.cache_data(f, article)
if not restrict_all_articles_to_tags <= set(
getattr(article, 'tags', [])):
continue
if article.status == "published":
all_articles.append(article)
elif article.status == "draft":