@@ -1050,6 +1050,7 @@ class Context(object):
1050
1050
Optional (r'autolinks' ): {str : str },
1051
1051
Optional (r'badges' ): {str : ValueOrArray (str , name = r'badges' , length = 2 )},
1052
1052
Optional (r'changelog' ): Or (str , bool ),
1053
+ Optional (r'main_page' ): Or (str , bool ),
1053
1054
Optional (r'code_blocks' ): CodeBlocks .schema ,
1054
1055
Optional (r'cpp' ): Or (str , int , error = r'cpp: expected string or integer' ),
1055
1056
Optional (r'defines' ): {str : Or (str , int , bool )}, # legacy
@@ -1560,7 +1561,11 @@ def add_internal_asset(p) -> str:
1560
1561
):
1561
1562
self .changelog = candidate_file
1562
1563
break
1563
- if self .changelog or candidate_dir .parent == candidate_dir :
1564
+ if (
1565
+ self .changelog
1566
+ or candidate_dir .parent == candidate_dir
1567
+ or (candidate_dir / '.git' ).exists ()
1568
+ ):
1564
1569
break
1565
1570
candidate_dir = candidate_dir .parent
1566
1571
if not self .changelog :
@@ -1580,6 +1585,47 @@ def add_internal_asset(p) -> str:
1580
1585
self .changelog = temp_changelog_path
1581
1586
self .verbose_value (r'Context.changelog' , self .changelog )
1582
1587
1588
+ # main_page (USE_MDFILE_AS_MAINPAGE)
1589
+ self .main_page = ''
1590
+ if r'main_page' in config :
1591
+ if isinstance (config ['main_page' ], bool ):
1592
+ if config ['main_page' ]:
1593
+ candidate_names = (r'README' , r'HOME' , r'MAINPAGE' , r'INDEX' )
1594
+ candidate_extensions = (r'.md' , r'.txt' , r'' )
1595
+ as_lowercase = (False , True )
1596
+ candidate_dir = self .input_dir
1597
+ while True :
1598
+ for name , ext , lower in itertools .product (
1599
+ candidate_names , candidate_extensions , as_lowercase
1600
+ ):
1601
+ candidate_file = Path (candidate_dir , rf'{ name .lower () if lower else name } { ext } ' )
1602
+ if (
1603
+ candidate_file .exists ()
1604
+ and candidate_file .is_file ()
1605
+ and candidate_file .stat ().st_size <= 1024 * 1024 * 2
1606
+ ):
1607
+ self .main_page = candidate_file
1608
+ break
1609
+ if (
1610
+ self .main_page
1611
+ or candidate_dir .parent == candidate_dir
1612
+ or (candidate_dir / '.git' ).exists ()
1613
+ ):
1614
+ break
1615
+ candidate_dir = candidate_dir .parent
1616
+ if not self .main_page :
1617
+ self .warning (
1618
+ rf'main_page: Option was set to true but no file with a known main_page file name could be found! Consider using an explicit path.'
1619
+ )
1620
+
1621
+ else :
1622
+ self .main_page = coerce_path (config ['main_page' ])
1623
+ if not self .main_page .is_absolute ():
1624
+ self .main_page = Path (self .input_dir , self .main_page )
1625
+ if not self .main_page .exists () or not self .main_page .is_file ():
1626
+ raise Error (rf'main_page: { config ["main_page" ]} did not exist or was not a file' )
1627
+ self .verbose_value (r'Context.main_page' , self .main_page )
1628
+
1583
1629
# sources (INPUT, FILE_PATTERNS, STRIP_FROM_PATH, STRIP_FROM_INC_PATH, EXTRACT_ALL)
1584
1630
self .sources = Sources (
1585
1631
config ,
0 commit comments