From f4d934801dfbd16494ce7e8cdafe74da639df83c Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 24 Apr 2026 19:41:58 +0300 Subject: [PATCH 1/2] Add validation for excluded page links in build tests --- mkdocs/structure/pages.py | 5 ++++- mkdocs/tests/build_tests.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/mkdocs/structure/pages.py b/mkdocs/structure/pages.py index b5115fdd..477c4160 100644 --- a/mkdocs/structure/pages.py +++ b/mkdocs/structure/pages.py @@ -17,6 +17,7 @@ from mkdocs import utils from mkdocs.structure import StructureItem +from mkdocs.structure.files import InclusionLevel from mkdocs.structure.toc import get_toc from mkdocs.utils import ( _removesuffix, @@ -533,10 +534,12 @@ def path_to_url(self, url: str) -> str: if target_file.inclusion.is_excluded(): if self.file.inclusion.is_excluded(): warning_level = logging.DEBUG - else: + elif target_file.inclusion is InclusionLevel.DRAFT: warning_level = min( logging.INFO, self.config.validation.links.not_found ) + else: + warning_level = self.config.validation.links.not_found warning = ( f"Doc file '{self.file.src_uri}' contains a link to " f"'{target_uri}' which is excluded from the built site." diff --git a/mkdocs/tests/build_tests.py b/mkdocs/tests/build_tests.py index 1d2461c2..bd842a4f 100644 --- a/mkdocs/tests/build_tests.py +++ b/mkdocs/tests/build_tests.py @@ -703,6 +703,29 @@ def test_draft_pages_with_invalid_links(self, site_dir, docs_dir): self.assertPathNotExists(site_dir, ".zoo.html") + @tempdir( + files={ + "index.md": "[asdf](./asdf.md)", + "asdf.md": "excluded content", + } + ) + @tempdir() + def test_excluded_page_link_uses_not_found_validation_level( + self, site_dir, docs_dir + ): + cfg = load_config( + docs_dir=docs_dir, + site_dir=site_dir, + validation=dict(links=dict(not_found="warn")), + exclude_docs="/asdf.md", + ) + + expected_logs = """ + WARNING:Doc file 'index.md' contains a link to 'asdf.md' which is excluded from the built site. + """ + with self._assert_build_logs(expected_logs): + build.build(cfg) + @tempdir( files={ "foo/README.md": "page1 content", From 7a2cd3f5f8d8a72ad0c3d796931b692dc604ea93 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 24 Apr 2026 19:51:30 +0300 Subject: [PATCH 2/2] Fix validation message for excluded pages in release notes Co-authored-by: Copilot --- docs/about/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/about/release-notes.md b/docs/about/release-notes.md index b0e1ef60..2ace8d11 100644 --- a/docs/about/release-notes.md +++ b/docs/about/release-notes.md @@ -28,6 +28,7 @@ The current members of the MkDocs-NG team. ### Fixed * Fix anchor link validation so `mkdocs build -v --strict` still fails when missing anchors are reported as warnings. #30 +* Fix `validation.links.not_found` is always reported as INFO for excluded pages. #32 ### Maintenance