lukasgeiter / mkdocs-awesome-pages-plugin

An MkDocs plugin that simplifies configuring page titles and their order
MIT License
452 stars 35 forks source link

Ordering breaks when rest pattern is used in mkdocs > nav #86

Open ketrab2004 opened 9 months ago

ketrab2004 commented 9 months ago

I work on a small project so I only want a single .pages file to control the entire structure of the site. But that isn't really possible with this issue, when you use folders.

Example file structure:

* index.md
* extras.md
* documentation/
    * main.md
    * systems/
        * index.md
        * coolSystem.md
    * plugins.md

.pages

nav:
    - Home: index.md
    - Documentation:
        - Main: documentation/main
        - Systems:
            - ... | documentation/*
        - Plugins: documentation/plugins
    - Extras: extras.md

Here the Documentation>Systems sidebar item has nothing under it. Clicking on it just links to the root. When I change the pattern to be regex it also doesn't work.

lukasgeiter commented 9 months ago

The ... in a .pages file only targets the remaining items in the directory of the .pages file. Try putting the nav block into mkdocs.yml instead.

ketrab2004 commented 9 months ago

For me ... shows everything, also in subdirectories. And adding a filter like *r* correctly finds everything that has an r in it, also in subdirectories. (but only in the file name itself, not in directories' names)

But putting the nav into mkdocs.yml works great (after adding .md), except now it doesn't order correctly under Documentation for some reason. But it does work correctly for outside of Documentation.

nav:
    - Home: index.md
    - Documentation:
        - Main: documentation/main.md
        - Systems:
            - ... | documentation/*
        - Plugins: documentation/plugins.md
    - Extras: extras.md

resulting sidebar

* Home
* Documentation
    * Plugins
    * Main
    * Systems
* Extras
lukasgeiter commented 9 months ago

documentation/* doesn't match any files, you would need something like documentation/**. But that's probably also not what you want so you would have to make it ... | flat | documentation/**.

This would be a lot easier if you would use two .pages files. Your navigation structure matches the file structure 1:1 so you only have to tweak the order of the items in the root and under documentation.

ketrab2004 commented 9 months ago

For me /*, /** and /**/* all work and match the same files.

Also my example nav isn't completely accurate, it is more something like this:

nav:
    - Home: index.md
    - Documentation:
        - Main: documentation/main.md
        - Systems:
            - ... | documentation/systems/*
        - Plugins: documentation/plugins.md
    - ... | other/*
    - Extras: extras.md

But now that I have added the ... | other/* the ordering of everything, not only under Documentation, does not match the nav. I can't really tell on what the order is based.

I haven't yet tried using multiple .pages files, but I don't think that should affect the ordering.

Since the issue topic has moved from rest filter patterns (though I don't really know why it didn't work within the .pages but does in mkdocs.yml) to ordering should I rename the issue?

lukasgeiter commented 9 months ago

Sure documentation/systems/* works, but before you wrote documentation/*.

The ordering being off likely means that the plugin is not doing anything at all for some reason. But feel free to rename the issue - I don't really mind.

Without all the information it's hard to diagnose what's happening. Could you send me a full example to reproduce your problem?

ketrab2004 commented 9 months ago

Here is a reproduction example: https://github.com/ketrab2004/awesome-pages-issue-repro

It does use the section/page name and the rest filter pattern correctly, only the ordering is incorrect.

lukasgeiter commented 9 months ago

Thanks for the example! There is a strange interaction between defining the navigation in mkdocs.yml and using the order option. Once again, I really recommend using separate files.

  1. Remove nav and filename: none from mkdocs.yml
  2. Add .pages in thedocs` folder:
    nav:
    - index.md
    - documentation
    - other.md
    - extras
  3. Add .pages in the documentation folder:
    nav:
    - Main: main.md
    - systems
    - Plugins: plugins.md