@@ -571,6 +571,66 @@ def _assert_build_logs(self, expected):
571571 del msgs [- 1 ]
572572 self .assertEqual ('\n ' .join (msgs ), textwrap .dedent (expected ).strip ('\n ' ))
573573
574+ @tempdir (
575+ files = {
576+ 'foo_unpublished.md' : 'unpublished content to include anyway' ,
577+ 'other_unpublished.md' : 'unpublished content' ,
578+ 'normal_file.md' : 'should not be affected' ,
579+ 'test/other_unpublished.md' : 'more unpublished content' ,
580+ 'test/normal_file.md' : 'should not be affected' ,
581+ }
582+ )
583+ @tempdir ()
584+ def test_draft_docs_with_comments_from_user_guide (self , site_dir , docs_dir ):
585+ cfg = load_config (
586+ docs_dir = docs_dir ,
587+ site_dir = site_dir ,
588+ use_directory_urls = False ,
589+ draft_docs = '''
590+ # A "drafts" directory anywhere.
591+ drafts/
592+
593+ # A Markdown file ending in _unpublished.md anywhere.
594+ *_unpublished.md
595+
596+ # But keep this particular file.
597+ !/foo_unpublished.md
598+ ''' ,
599+ )
600+
601+ with self .subTest (serve_url = None ):
602+ build .build (cfg )
603+ self .assertPathIsFile (site_dir , 'foo_unpublished.html' )
604+ self .assertPathIsFile (site_dir , 'normal_file.html' )
605+ self .assertPathIsFile (site_dir , 'test' , 'normal_file.html' )
606+ self .assertPathNotExists (site_dir , 'other_unpublished.html' )
607+ self .assertPathNotExists (site_dir , 'test' , 'other_unpublished.html' )
608+
609+ serve_url = 'http://localhost:123/documentation/'
610+ with self .subTest (serve_url = serve_url ):
611+ expected_logs = '''
612+ INFO:The following pages are being built only for the preview but will be excluded from `mkdocs build` per `draft_docs` config:
613+ - http://localhost:123/documentation/other_unpublished.html
614+ - http://localhost:123/documentation/test/other_unpublished.html
615+ '''
616+ with self ._assert_build_logs (expected_logs ):
617+ build .build (cfg , serve_url = serve_url )
618+
619+ top_other_path = Path (site_dir , 'other_unpublished.html' )
620+ self .assertTrue (top_other_path .is_file ())
621+ self .assertIn ('DRAFT' , top_other_path .read_text ())
622+
623+ sub_other_path = Path (site_dir , 'test' , 'other_unpublished.html' )
624+ self .assertPathIsFile (sub_other_path )
625+ self .assertIn ('DRAFT' , sub_other_path .read_text ())
626+
627+ self .assertPathIsFile (site_dir , 'foo_unpublished.html' )
628+ self .assertPathIsFile (site_dir , 'normal_file.html' )
629+
630+ good_path = Path (site_dir , 'test' , 'normal_file.html' )
631+ self .assertPathIsFile (good_path )
632+ self .assertNotIn ('DRAFT' , good_path .read_text ())
633+
574634 @tempdir (
575635 files = {
576636 'test/foo.md' : 'page1 content, [bar](bar.md)' ,
0 commit comments