Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include page data in navigation entry #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion eleventy-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ function findNavigationEntries(nodes = [], key = "") {
if(entry.data && entry.data.eleventyNavigation) {
let nav = entry.data.eleventyNavigation;
if(!key && !nav.parent || nav.parent === key) {
// Extract the page data without the eleventyNavigation key
const {eleventyNavigation, ...pageDataWithoutNav} = entry.data
pages.push(Object.assign({}, nav, {
url: nav.url || entry.data.page.url,
pluginType: "eleventy-navigation"
}, key ? { parentKey: key } : {}));
}, key ? { parentKey: key } : {},
{ data: pageDataWithoutNav }));
}
}
}
Expand Down
26 changes: 25 additions & 1 deletion test/navigationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,28 @@ test("Output markdown", t => {
* [child1](child1.html)
* [grandchild1](grandchild1.html)
`);
});
});

test("Navigation entry contains page data", t => {
let obj = EleventyNavigation.findNavigationEntries([
{
data: {
eleventyNavigation: {
key: "root1"
},
page: {
url: "root1.html"
},
tags: [
"robot",
"lesbian"
]
}
}
]);

// Page data like tags should be included in the obj
t.deepEqual(obj[0].data.tags, ["robot", "lesbian"])
// Don't include the eleventyNavigation data inside the returned data
t.false(obj[0].data.hasOwnProperty("eleventyNavigation"))
});