mkdocs-awesome-nav

repository·main·Indexed 20 days ago

https://github.com/lukasgeiter/mkdocs-awesome-nav

A MkDocs plugin for granular control over site navigation structure. It enables custom ordering, external links, visibility toggling, and the use of glob patterns to automate navigation without manually defining the entire structure in mkdocs.yml. Key features include flattening single-child sections, hiding pages via ignore patterns, and advanced sorting options.

Tokens
6.4K
Snippets
30
Records
41
Agent score
70%

What's inside mkdocs-awesome-nav

  1. Overview of mkdocs-awesome-nav

    main

    The mkdocs-awesome-nav plugin (formerly mkdocs-awesome-pages-plugin) provides advanced control over the MkDocs navigation structure. It allows you to manipulate the navigation tree without manually defining the entire structure in mkdocs.yml.

    Key capabilities include:

    • Adjusting Item Order: Manually re-order items or use sorting options.
    • Adding Sections & Links: Create new navigation sections and include external links.
    • Customizing Titles: Override section titles or specific page titles.
    • Hiding Pages: Hide specific pages or entire sections from the navigation menu (they remain accessible via URL).
    • Using Glob Patterns: Use glob patterns to match and show/hide files.
  2. How configuration inheritance works in .nav.yml

    main
    Settings defined in a .nav.yml file are inherited by all child directories. This means you can apply global navigation rules or structural changes by placing a single .nav.yml file at the root of your documentation directory (docs/.nav.yml), which will then affect the entire site structure.
  3. How to customize navigation with awesome-nav

    main

    The awesome-nav plugin provides granular control over your MkDocs navigation without requiring you to manually define the entire structure in mkdocs.yml. Instead of the standard MkDocs approach, awesome-nav generates navigation based on your file structure and allows you to apply specific customizations using .nav.yml files placed within your docs directory.

    To use this feature, create a .nav.yml file in any directory within your docs folder. This file allows you to augment or override the automatically generated structure for that specific directory and its children.

  4. Understand the scope of awesome-nav customization

    main
    The awesome-nav plugin is strictly limited to customizing the navigation structure (the hierarchy, order, and grouping of pages). It does not control how the links are visually rendered in the browser. For visual styling, CSS, or changes to the link appearance, you should use MkDocs theme configurations.
  5. Migrate from mkdocs-awesome-pages-plugin (v2) to mkdocs-awesome-nav (v3)

    main

    To upgrade from version 2 to version 3, follow these steps:

    1. Uninstall the old plugin: pip uninstall mkdocs-awesome-pages-plugin
    2. Install the new plugin: pip install mkdocs-awesome-nav
    3. Update mkdocs.yml: Replace awesome-pages with awesome-nav in the plugins list.
    4. Update configuration files: Rename .pages files to .nav.yml (recommended) and update the syntax according to the changes in mkdocs.yml and .nav.yml configuration keys.
    # Example mkdocs.yml update
    plugins:
      - awesome-nav
  6. Insert individual pages into navigation

    main

    You can insert specific markdown files into your navigation by referencing their path. You can also override the display title using the Title: path/to/file.md syntax.

    Note that files can be located in subdirectories relative to the .nav.yml file.

    nav:
      - support.md          # Standard reference
      - help/support.md     # Reference in a subdirectory
      - Help: support.md   # Reference with an overridden title
  7. Use glob patterns to automate navigation

    main

    You can use glob patterns to automatically include all files or directories that match a specific pattern. This is powered by wcmatch with GLOBSTAR and EXTGLOB flags enabled.

    Important: Patterns starting with * must be wrapped in quotes to avoid YAML alias errors.

    Key Behaviors:

    • No repeated matches: Glob patterns will never match files or directories that are already explicitly defined elsewhere in the nav configuration.
    • Flattening: Matching files and directories are inserted as a flat list (sorted by path by default).
    nav:
      - "*"               # Matches everything in current directory
      - "*.md"            # Matches only markdown files
      - "*/"              # Matches only directories
      - "*.public.md"     # Matches files with a specific suffix
      - "*.@(public|published).md" # Logical OR pattern
      - "**/*.md"         # Deep match: all markdown files in all subdirectories
      - "*/index.md"      # One level deep: index files in subdirectories
  8. Insert directories as navigation sections

    main

    To insert an entire directory as a section in your navigation, reference the directory name. If the directory contains its own .nav.yml file, that file will be used to generate the section, but a title defined in the parent .nav.yml will take precedence.

    You can also override the section title using the Title: directory_name syntax.

    nav:
      - guides             # Standard directory reference
      - resources/guides   # Sub-directory reference
      - User Guides: guides # Reference with an overridden title
  9. Customize navigation sorting with .nav.yml

    main

    You can customize the sorting of pages and sections using a .nav.yml file. These settings affect all items that are not explicitly ordered using the nav key in your configuration.

    Inheritance: Sorting options apply to all child directories unless they are overridden by a local .nav.yml file within that directory.

    sort:
      direction: asc
      sections: last
      type: natural
      by: path
  10. Hide pages using ignore patterns

    main

    You can hide specific directories and pages from the navigation using .gitignore-style glob patterns via the ignore key in a .nav.yml file.

    Important: If your pattern starts with *, you must wrap it in quotes to prevent YAML parsing errors (as * is reserved for aliases in YAML).

    Patterns are inherited by child directories unless overridden by a local .nav.yml file.

    ignore: "*.hidden.md"