@@ -369,7 +369,7 @@ def purge_css(css: str, html_content: str) -> str:
369
369
# Serialise the new stylesheet
370
370
return new_stylesheet .cssText .decode ('utf-8' )
371
371
372
- def convert_to_html (filenames : List [str ], css : str , macros : dict , transforms : List [Callable [[str ], str ]], project ) -> List [str ]:
372
+ def convert_to_html (filenames : List [str ], css : str , macros : dict , transforms : List [Callable [[str ], str ]], project : str , top_level_files : List [ str ] ) -> List [str ]:
373
373
"""
374
374
Convert each Markdown file and convert to HTML, using the same rendering library as
375
375
mkdocs, with the same set of extensions. We expand the mkdocs-macro {{ templates }}
@@ -392,14 +392,18 @@ def convert_to_html(filenames: List[str], css: str, macros: dict, transforms: Li
392
392
converted : List [str ] = []
393
393
394
394
for file in filenames :
395
- # Handle both root-level files and files in docs subdirectories
396
- if '/docs/' in file :
395
+ if file in top_level_files :
396
+ # Top-level files go directly in project/
397
+ newname = os .path .basename (file ).replace ('.md' , '.htm' )
398
+ elif '/docs/' in file :
399
+ # Sub-site files go in project/sub-site/
397
400
path , oldname = file .split ('/docs/' , maxsplit = 1 )
398
- newname = str (os .path .join (os .path .basename (path ), oldname .replace ('.md' , '.htm' )))
401
+ sub_site = os .path .basename (path )
402
+ newname = os .path .join (sub_site , oldname .replace ('.md' , '.htm' ))
399
403
else :
400
- # For root-level files, just use the basename
404
+ # Fallback for files without /docs/
401
405
newname = os .path .basename (file ).replace ('.md' , '.htm' )
402
-
406
+
403
407
realpath_newname = str (os .path .join (project , newname ))
404
408
os .makedirs (os .path .dirname (realpath_newname ), exist_ok = True )
405
409
@@ -581,22 +585,31 @@ def write_index_data(entries: List[Tuple[str, str]], filename: str) -> None:
581
585
idxfh .write ("</body></html>\n " )
582
586
583
587
584
- def find_toplevel_dirs (filename : str , remove : List [str ]) -> List [str ]:
588
+ def find_nav_files_and_dirs (filename : str , remove : List [str ]) -> Tuple [ List [str ], List [ str ] ]:
585
589
"""
586
- Find the toplevel document dirs -- these are the ones that are
587
- pulled into the main mkdocs.yml file via !include
590
+ Extract both top-level directories (from !include directives) and standalone Markdown files
591
+ directly listed in the nav section of the mkdocs.yml file.
592
+
593
+ Returns:
594
+ Tuple[List[str], List[str]]: (included_dirs, standalone_files)
588
595
"""
589
596
yaml = YAML ()
590
- with ( open (filename , 'r' , encoding = 'utf-8' ) ) as f :
597
+ with open (filename , 'r' , encoding = 'utf-8' ) as f :
591
598
data = yaml .load (f )
592
- tlds = []
599
+
600
+ included_dirs = []
601
+ standalone_files = []
602
+
593
603
for d in data ['nav' ]:
594
604
key , value = next (iter (d .items ()))
595
605
if key not in remove :
596
- if m := re .match (r'!include\s+([^"]+)' , value ):
597
- tlds .append (m .group (1 ))
598
-
599
- return tlds
606
+ if isinstance (value , str ):
607
+ if m := re .match (r'!include\s+([^"]+)' , value ):
608
+ included_dirs .append (m .group (1 )) # Path from !include
609
+ elif value .endswith ('.md' ):
610
+ standalone_files .append (os .path .join ('docs' , value )) # Direct .md file reference
611
+
612
+ return included_dirs , standalone_files
600
613
601
614
602
615
def generate_hfp (project : str , chmfile : str , files : List [str ], images : List [str ], assets : List [str ], title : str ) -> None :
@@ -878,9 +891,7 @@ def filter_unused_images(md_files: List[str], css_files: List[str], image_files:
878
891
879
892
os .makedirs (args .project_dir , exist_ok = True )
880
893
881
- # Parse the nav section. If this is a monorepo (in 99% of the cases it will be),
882
- # macro-expand any !include directives
883
-
894
+ # Parse config for excludes
884
895
excludes = []
885
896
if args .config :
886
897
try :
@@ -890,15 +901,22 @@ def filter_unused_images(md_files: List[str], css_files: List[str], image_files:
890
901
except (json .JSONDecodeError , FileNotFoundError ) as e :
891
902
sys .exit (f'--> Error reading config file: { e } ' )
892
903
904
+ # Parse mkdocs.yml
893
905
yml_data = parse_mkdocs_yml (args .mkdocs_yml , remove = excludes )
894
- includes = find_toplevel_dirs (args .mkdocs_yml , remove = excludes )
906
+
907
+ # Find top-level dirs and standalone files from nav
908
+ included_dirs , standalone_files = find_nav_files_and_dirs (args .mkdocs_yml , remove = excludes )
895
909
896
910
version = yml_data ["extra" ].get ("version_majmin" )
897
911
if not version :
898
912
sys .exit (f'--> source mkdocs.yml has no Dyalog version set' )
899
913
900
- # Find all source Markdown files and images
901
- md_files , image_files = find_source_files (os .path .dirname (args .mkdocs_yml ), includes )
914
+ # Find all source Markdown files from included directories
915
+ md_files_from_dirs , image_files = find_source_files (os .path .dirname (args .mkdocs_yml ), included_dirs )
916
+
917
+ # Add standalone Markdown files from nav, with absolute paths
918
+ standalone_files_abs = [os .path .abspath (os .path .join (os .path .dirname (args .mkdocs_yml ), f )) for f in standalone_files ]
919
+ md_files = md_files_from_dirs + standalone_files_abs
902
920
903
921
# Add welcome.md to the start of the files list
904
922
md_files .insert (0 , os .path .abspath (args .welcome ))
@@ -928,7 +946,8 @@ def filter_unused_images(md_files: List[str], css_files: List[str], image_files:
928
946
transforms = [
929
947
table_captions
930
948
],
931
- project = args .project_dir
949
+ project = args .project_dir ,
950
+ top_level_files = standalone_files_abs
932
951
)
933
952
934
953
# Generate the CHM ToC
@@ -942,7 +961,6 @@ def filter_unused_images(md_files: List[str], css_files: List[str], image_files:
942
961
943
962
# Generate the CHM project config file
944
963
chm_name = "dyalog.chm"
945
-
946
964
generate_hfp (args .project_dir , chm_name , html_files , copied_images , assets , title = f'Dyalog version { version } ' )
947
965
948
966
# Run the compiler
0 commit comments