@@ -603,17 +603,11 @@ def _generate_categories(self, config: MkDocsConfig, files: Files):
603603 def _generate_pages (self , view : View , config : MkDocsConfig , files : Files ):
604604 yield view
605605
606- # Compute base path for pagination - if the given view is an index file,
607- # we need to pop the file name from the base so it's not part of the URL
608- base , _ = posixpath .splitext (view .file .src_uri )
609- if view .file .name == "index" :
610- base = posixpath .dirname (base )
611-
612606 # Compute pagination boundaries and create pages - pages are internally
613607 # handled as copies of a view, as they map to the same source location
614608 step = self .config .pagination_per_page
615609 for at in range (step , len (view .posts ), step ):
616- path = self ._format_path_for_pagination (base , 1 + at // step )
610+ path = self ._format_path_for_pagination (view , 1 + at // step )
617611
618612 # Create file for view, if it does not exist
619613 file = files .get_file_from_path (path )
@@ -784,11 +778,20 @@ def _format_path_for_category(self, name: str):
784778 return posixpath .join (self .config .blog_dir , f"{ path } .md" )
785779
786780 # Format path for pagination
787- def _format_path_for_pagination (self , base : str , page : int ):
781+ def _format_path_for_pagination (self , view : View , page : int ):
788782 path = self .config .pagination_url_format .format (
789783 page = page
790784 )
791785
786+ # Compute base path for pagination - if the given view is an index file,
787+ # we need to pop the file name from the base so it's not part of the URL
788+ # and we need to append `index` to the path, so the paginated view is
789+ # also an index page - see https://t.ly/71MKF
790+ base , _ = posixpath .splitext (view .file .src_uri )
791+ if view .is_index :
792+ base = posixpath .dirname (base )
793+ path = posixpath .join (path , "index" )
794+
792795 # Normalize path and strip slashes at the beginning and end
793796 path = posixpath .normpath (path .strip ("/" ))
794797 return posixpath .join (base , f"{ path } .md" )
0 commit comments