From b49a0500e06296ba1efd58926e060772b6a8d866 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 13 Apr 2018 12:18:54 -0500 Subject: [PATCH] Add ARTICLE_RESTRICT_TO_TAGS setting --- docs/settings.rst | 6 ++++++ pelican/generators.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index 0ae26ca4..3ec7e9ff 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -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 diff --git a/pelican/generators.py b/pelican/generators.py index 069da0c1..2f5316da 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -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":