@@ -125,6 +125,9 @@ def on_files(self, files, *, config):
125
125
file .abs_dest_path = os .path .join (site , file .dest_path )
126
126
file .url = file .url .replace (path , root )
127
127
128
+ # Generate entrypoint, if it does not exist yet
129
+ self ._generate (files , config )
130
+
128
131
# Resolve and load posts and generate indexes (run later) - we resolve all
129
132
# posts after the navigation is constructed in order to allow other plugins
130
133
# to alter the navigation (e.g. awesome-pages) before we start to add pages
@@ -332,24 +335,12 @@ def _is_excluded(self, post: Post):
332
335
333
336
# -------------------------------------------------------------------------
334
337
335
- # Resolve entrypoint - the entrypoint of the blog hosts all posts, sorted
336
- # by descending date. The entrypoint must always be present, even if there
337
- # are no posts, and is automatically created if it does not exist yet. Note
338
- # that posts might be paginated, but this is configurable by the author.
338
+ # Resolve entrypoint - the entrypoint of the blog must have been created
339
+ # if it did not exist before, and hosts all posts sorted by descending date
339
340
def _resolve (self , files : Files , config : MkDocsConfig , nav : Navigation ):
340
341
path = os .path .join (self .config .blog_dir , "index.md" )
341
342
path = os .path .normpath (path )
342
343
343
- # Create entrypoint, if it does not exist
344
- docs = os .path .relpath (config .docs_dir )
345
- file = os .path .join (docs , path )
346
- if not os .path .isfile (file ):
347
- self ._save_to_file (file , "# Blog\n \n " )
348
-
349
- # Append entrypoint to files - note that the entrypoint is added to
350
- # the docs directory, so we need to set the temporary flag to false
351
- files .append (self ._path_to_file (path , config , temp = False ))
352
-
353
344
# Obtain entrypoint page
354
345
file = files .get_file_from_path (path )
355
346
page = file .page
@@ -525,6 +516,23 @@ def _attach_to(self, view: View, section: Section, nav: Navigation):
525
516
526
517
# -------------------------------------------------------------------------
527
518
519
+ # Generate entrypoint - the entrypoint must always be present, and thus is
520
+ # created before the navigation is constructed if it does not exist yet
521
+ def _generate (self , files : Files , config : MkDocsConfig ):
522
+ path = os .path .join (self .config .blog_dir , "index.md" )
523
+ path = os .path .normpath (path )
524
+
525
+ # Create entrypoint, if it does not exist - note that the entrypoint is
526
+ # added to the docs directory, not to the temporary directory
527
+ docs = os .path .relpath (config .docs_dir )
528
+ file = os .path .join (docs , path )
529
+ if not os .path .isfile (file ):
530
+ file = self ._path_to_file (path , config , temp = False )
531
+ self ._save_to_file (file .abs_src_path , "# Blog\n \n " )
532
+
533
+ # Append entrypoint to files
534
+ files .append (file )
535
+
528
536
# Generate views for archive - analyze posts and generate the necessary
529
537
# views, taking the date format provided by the author into account
530
538
def _generate_archive (self , config : MkDocsConfig , files : Files ):
@@ -539,11 +547,11 @@ def _generate_archive(self, config: MkDocsConfig, files: Files):
539
547
file = files .get_file_from_path (path )
540
548
if not file :
541
549
file = self ._path_to_file (path , config )
542
- files . append (file )
550
+ self . _save_to_file (file . abs_src_path , f"# { name } " )
543
551
544
552
# Create and yield archive view
545
- self ._save_to_file (file .abs_src_path , f"# { name } " )
546
553
yield Archive (name , file , config )
554
+ files .append (file )
547
555
548
556
# Assign post to archive
549
557
assert isinstance (file .page , Archive )
@@ -570,11 +578,11 @@ def _generate_categories(self, config: MkDocsConfig, files: Files):
570
578
file = files .get_file_from_path (path )
571
579
if not file :
572
580
file = self ._path_to_file (path , config )
573
- files . append (file )
581
+ self . _save_to_file (file . abs_src_path , f"# { name } " )
574
582
575
583
# Create and yield category view
576
- self ._save_to_file (file .abs_src_path , f"# { name } " )
577
584
yield Category (name , file , config )
585
+ files .append (file )
578
586
579
587
# Assign post to category and vice versa
580
588
assert isinstance (file .page , Category )
0 commit comments