A simple mkdocs plugin, enable to sort nav by setting "weight" in markdown metadata
Project description
mkdocs-nav-weight
A simple mkdocs plugin, enable to sort nav by setting "weight" in markdown metadata
Not sure if it works (at least it does in my local docs).
This plugin tries to read markdown resources before mkdocs, which may add some performance overhead
How it works
Get the weight
of each child of the folder (section
):
- if it is a
page
, try to get its value, return 0 on failure. - if it is a folder (
section
), then try to get the value from the child wichisindex=true
, return 0 on failure. - sort these children by
weight
.
Recursively all folders starting from docs
.
Install
pip install mkdocs-nav-weight
mkdocs.yml
plugins:
- search
- mkdocs-nav-weight
Options
mkdocs.yml
plugins:
- search
- mkdocs-nav-weight:
section_renamed: false
reverse: false
section_renamed
, defaultfalse
:- If
true
, section name will use thetitle
of itsindex
instead of the folder name. (For compatibility we have to name a folder like "c#" as "csharp", but what we actually want to see in the page is "c#" , that's what this option does)
- If
reverse
, defaultfalse
:- If
true
, sortnav
byweight
from largest to smallest.
- If
Example
Markdown metadata like this:
foo.md
---
title: foo
weight: 4
...
---
In the following, it is simply expressed as:
foo.md // 4
A document tree like this:
│ bar.md // no “weight”
│ foo.md // 4
│
├─have_index_folder
│ │ another.md // 1
│ │ index.md // 3
│ │
│ └─level2
│ another.md // 1
│ bar.md // no “weight”
│ foo.md // 4
│
└─no_index_folder
alone.md // 2
You will get a nav like this:
bar // 0: no 'weight', default 0
No index folder // 0: cann't find a 'index', so it's defalut 0
alone // 2
Have index folder // 3: get from 'index'
index // 0: it's 3 but as 0 in same level
Level2 // 0: no index, default 0
bar // 0
another // 1
foo // 4
another // 1
foo // 4
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for mkdocs_nav_weight-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5d974dc6979654126e17f7fb99302427528d17a5964d9c834613f3c4838de1e |
|
MD5 | 37a0b32d8b08f19345a914c7bee7ccba |
|
BLAKE2b-256 | 495954f3125230233deb533419903a3e2070154546a0aba50339a5851ac17bf5 |