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

fix: disallow repeated segments at end of path #189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions blocks/sidenav/sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,11 @@ function bookToList(book) {
// add the chapter
const chapterUl = addSubList(
chapter.name,
`${book.path}/${chapter.key}/${chapter.key}`,
`${book.path}/${chapter.key}`,
chapter.key,
);

const makeHref = (topic, parentKey) => `${book.path}/${chapter.key}/${parentKey ? `${parentKey}/` : ''}${topic.key}`;
const makeHref = (topic, parentKey) => `${book.path}/${chapter.key}/${parentKey ? (`${parentKey}${parentKey.endsWith(`/${topic.key}`) ? '' : `/${topic.key}`}`) : topic.key}`;

// then the topics recursively
const processTopic = (topic, parentKey) => {
Expand All @@ -621,18 +621,19 @@ function bookToList(book) {

addSubList(
topic.name,
`${book.path}/${chapter.key}/${parentKey ? `${parentKey}/` : ''}${topic.key}/${
topic.key
}`,
makeHref(topic, parentKey),
topic.key,
);

topic.children.forEach((subtopic) => {
if (subtopic.key === topic.key && !subtopic.children) {
// uncomment to omit entries in sidenav with same link as parent
// return;
}

processTopic(
subtopic,
`${parentKey ? `${parentKey}/` : ''}${topic.key}${
subtopic.parent ? `/${subtopic.parent}` : ''
}`,
`${parentKey ? `${parentKey}/` : ''}${topic.key}`,
);
});

Expand Down