Skip to content

Commit

Permalink
nav.menu().toJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Aug 26, 2024
1 parent 8f6a479 commit e50c305
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Go to the `v1` branch to see the changelog of Lume 1.
- New plugin `sri`.
- Improved plugin docs with links to the online documentation.
- New functions `nav.nextPage()` and `nav.previousPage()` for `nav` plugin.
- New method `toJSON()` added to the result of `nav.menu()` for `nav` plugin.
For example:
```js
const menu = nav.menu();
JSON.stringify(menu);
```
- New sort options `asc-locale` and `desc-locale`.

### Changed
Expand Down
20 changes: 20 additions & 0 deletions plugins/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ export interface NavData {
data: Data;
children?: NavData[];
parent?: NavData;
toJSON(): NavJSON;
}

export interface NavJSON {
data: {
title?: string;
url?: string;
basename: string;
};
children?: NavJSON[];
}

function getNextChild(item: NavData): Data | undefined {
Expand Down Expand Up @@ -276,6 +286,16 @@ function convert(
const data: NavData = {
data: temp.data,
parent,
toJSON() {
return {
data: {
title: this.data.title,
url: this.data.url,
basename: this.data.basename,
},
children: this.children?.map((child) => child.toJSON()),
};
},
};

data.children = temp.children
Expand Down

0 comments on commit e50c305

Please sign in to comment.