Skip to content

Commit

Permalink
Add new global attribute fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkrzyskow committed Mar 16, 2023
1 parent f83d427 commit 307002d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ plugins:
filename: .index
collapse_single_pages: true
strict: false
order: asc
sort_type: natural
```

### `filename`
Expand All @@ -399,6 +401,10 @@ Raise errors instead of warnings when:

Default is `true`

### `order` and `sort_type`

Global fallback values for the Meta attributes. Default is `None`.

<br/>

## Contributing
Expand Down
3 changes: 2 additions & 1 deletion mkdocs_awesome_pages_plugin/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def _process_children(self, children: List[NavigationItem], collapse: bool, meta
return result

def _order(self, items: List[NavigationItem], meta: Meta):
order, sort_type = meta.order, meta.sort_type
order = meta.order or self.options.order
sort_type = meta.sort_type or self.options.sort_type
if order is None and sort_type is None:
return
key = lambda i: basename(self._get_item_path(i))
Expand Down
6 changes: 5 additions & 1 deletion mkdocs_awesome_pages_plugin/options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class Options:
def __init__(self, *, filename: str, collapse_single_pages: bool, strict: bool):
def __init__(
self, *, filename: str, collapse_single_pages: bool, strict: bool, order: str = None, sort_type: str = None
):
self.filename = filename
self.collapse_single_pages = collapse_single_pages
self.strict = strict
self.order = order
self.sort_type = sort_type
2 changes: 2 additions & 0 deletions mkdocs_awesome_pages_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class AwesomePagesPlugin(BasePlugin):
("filename", config_options.Type(str, default=DEFAULT_META_FILENAME)),
("collapse_single_pages", config_options.Type(bool, default=False)),
("strict", config_options.Type(bool, default=True)),
("order", config_options.Choice(["asc", "desc"], default=None)),
("sort_type", config_options.Choice(["natural"], default=None)),
)

def __init__(self):
Expand Down

0 comments on commit 307002d

Please sign in to comment.