Repository: ovasquez/mkdocs-merge

Issue:
Add support for section index pages
Hey there!

Firstly, thank you so much for this amazing tool!

In our company, we use it in combo with [MkDocs Material](https://squidfunk.github.io/mkdocs-material/). Not sure about original MkDocs, but in this version, there is an option to set index pages for sections. To get a better understanding, please take a look at [feature description](https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/#section-index-pages).

It's very simple, and what it means, is that basically you may now have a nav entry in `mkdocs.yml` that looks like this:
```yaml
nav:
  - Home: index.md
  - Section:
    - section/index.md                             #   <--- this right here is new!
    - Page 1: section/page-1.md
    ...
    - Page n: section/page-n.md
```

Those kind of entries are currently not supported and result in "Error merging the "nav" entry in the site:   xxxx".

I've taken a quick look at the code - to me seems like a new elif in recursive function `update_navs` should be added where `nav` can be instance of `str`, or sth like that. 

I hope you'll have a bit of time to consider this.

Thanks!

Discussion:
ovasquez: Hi @Acerinth, thanks for the interest in this tool and for adding support for this feature! 💯 
Do you know how this new item would look like in a test like the ones written in this file? https://github.com/ovasquez/mkdocs-merge/blob/main/mkdocsmerge/tests/merge_test.py
I ask because I want to make sure this feature doesn't break in the future, so ideally we would have a test to make sure it keeps working as expected in future releases.
Acerinth: Hey @ovasquez , thanks for such a quick response!

Yes, definitely. I've already thought about it, but I wanted to check with you before implementation. Should I just adjust the mocks in all three existing tests, or do you want me to create a completely new test? As this is not a new function, but just a change to the existing one, to me the first option makes more sense. What do you think? 
ovasquez: @Acerinth I think a separate test would be better, because it can be focused on this feature, and in case it breaks, it would be easier to identify which feature broke. Does this make sense?
Acerinth: @ovasquez Sure, no problem. I've added a separate test now and double checked that it fails if my new 4 lines are not there ;) Is there anything else I should add/change?


Patch:
diff --git a/mkdocsmerge/merge.py b/mkdocsmerge/merge.py
index 5ed4499..279b9d4 100644
--- a/mkdocsmerge/merge.py
+++ b/mkdocsmerge/merge.py
@@ -147,7 +147,10 @@ def update_navs(navs, site_root, print_func):
     """
     if isinstance(navs, list):
         for page in navs:
-            update_navs(page, site_root, print_func)
+            if isinstance(page, str):
+                navs[navs.index(page)] = site_root + "/" + page
+            else:
+                update_navs(page, site_root, print_func)
     elif isinstance(navs, dict):
         for name, path in navs.items():
             if isinstance(path, str):


Test patch:
diff --git a/mkdocsmerge/tests/merge_test.py b/mkdocsmerge/tests/merge_test.py
index 62138e9..dee9cf0 100644
--- a/mkdocsmerge/tests/merge_test.py
+++ b/mkdocsmerge/tests/merge_test.py
@@ -113,3 +113,31 @@ class TestSiteMerges(unittest.TestCase):
         mkdocsmerge.merge.merge_single_site(
             global_nav, site_name, site_nav, True)
         self.assertEqual(global_nav, expected)
+
+    def test_update_pages_with_section_indexes(self):
+        """
+        Verifies the correct updating of the section index pages' paths.
+        """
+        # Create original and expected data structures
+        subpage = 'new_root'
+        subpage_path = subpage + '/'
+        nav = [{'Home': 'index.md'},
+               {'Projects': [
+                   'projects/index.md',
+                   {'Nested': [
+                       'projects/nested/index.md',
+                       {'Third': 'projects/nest/third.md'}
+                   ]}
+               ]}]
+
+        expected = [{'Home': subpage_path + 'index.md'},
+                    {'Projects': [
+                        subpage_path + 'projects/index.md',
+                        {'Nested': [
+                            subpage_path + 'projects/nested/index.md',
+                            {'Third': subpage_path + 'projects/nest/third.md'}
+                        ]}
+                    ]}]
+
+        mkdocsmerge.merge.update_navs(nav, subpage, lambda x: None)
+        self.assertEqual(nav, expected)