diff --git a/material/plugins/blog/plugin.py b/material/plugins/blog/plugin.py index 175fa7ae6..15d9b987e 100644 --- a/material/plugins/blog/plugin.py +++ b/material/plugins/blog/plugin.py @@ -34,9 +34,9 @@ from lxml.html import fragment_fromstring, tostring from mkdocs import utils from mkdocs.utils.meta import get_data from mkdocs.commands.build import _populate_page -from mkdocs.contrib.search import SearchIndex +from mkdocs.contrib.search.search_index import SearchIndex from mkdocs.plugins import BasePlugin -from mkdocs.structure.files import File, Files +from mkdocs.structure.files import File, Files, InclusionLevel from mkdocs.structure.nav import Link, Section from mkdocs.structure.pages import Page from tempfile import gettempdir @@ -234,6 +234,10 @@ class BlogPlugin(BasePlugin[BlogConfig]): # Add post metadata self.post_meta_map[file.src_uri] = meta + # Mark page as excluded, so it's not picked up by other plugins + if not self.config.draft and self._is_draft(file.src_uri): + file.inclusion = InclusionLevel.EXCLUDED + # Sort post metadata by date (descending) self.post_meta_map = dict(sorted( self.post_meta_map.items(), diff --git a/material/plugins/tags/plugin.py b/material/plugins/tags/plugin.py index 881599752..62bbeccdf 100644 --- a/material/plugins/tags/plugin.py +++ b/material/plugins/tags/plugin.py @@ -76,6 +76,10 @@ class TagsPlugin(BasePlugin[TagsConfig]): if not self.config.enabled: return + # Skip, if page is excluded + if page.file.inclusion.is_excluded(): + return + # Render tags index page if page.file == self.tags_file: return self._render_tag_index(markdown) diff --git a/src/plugins/blog/plugin.py b/src/plugins/blog/plugin.py index 175fa7ae6..15d9b987e 100644 --- a/src/plugins/blog/plugin.py +++ b/src/plugins/blog/plugin.py @@ -34,9 +34,9 @@ from lxml.html import fragment_fromstring, tostring from mkdocs import utils from mkdocs.utils.meta import get_data from mkdocs.commands.build import _populate_page -from mkdocs.contrib.search import SearchIndex +from mkdocs.contrib.search.search_index import SearchIndex from mkdocs.plugins import BasePlugin -from mkdocs.structure.files import File, Files +from mkdocs.structure.files import File, Files, InclusionLevel from mkdocs.structure.nav import Link, Section from mkdocs.structure.pages import Page from tempfile import gettempdir @@ -234,6 +234,10 @@ class BlogPlugin(BasePlugin[BlogConfig]): # Add post metadata self.post_meta_map[file.src_uri] = meta + # Mark page as excluded, so it's not picked up by other plugins + if not self.config.draft and self._is_draft(file.src_uri): + file.inclusion = InclusionLevel.EXCLUDED + # Sort post metadata by date (descending) self.post_meta_map = dict(sorted( self.post_meta_map.items(), diff --git a/src/plugins/tags/plugin.py b/src/plugins/tags/plugin.py index 881599752..62bbeccdf 100644 --- a/src/plugins/tags/plugin.py +++ b/src/plugins/tags/plugin.py @@ -76,6 +76,10 @@ class TagsPlugin(BasePlugin[TagsConfig]): if not self.config.enabled: return + # Skip, if page is excluded + if page.file.inclusion.is_excluded(): + return + # Render tags index page if page.file == self.tags_file: return self._render_tag_index(markdown)