Skip to content

Commit

Permalink
Merge pull request #531 from MinBZK/fix-breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
onursagir authored May 10, 2024
2 parents 751c185 + ebe700b commit 94197af
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-pants-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"web": patch
---

Fixed submenus not showing when there is a cover image on the page
5 changes: 5 additions & 0 deletions .changeset/strange-mice-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"web": patch
---

Fixed breadcrumbs not rendering properly when parent of node isn't present
1 change: 1 addition & 0 deletions apps/web/src/app/menu-desktop.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
z-index: 40;
}

@keyframes scaleIn {
Expand Down
48 changes: 28 additions & 20 deletions apps/web/src/services/cms/get-navbar-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,34 @@ export type NavbarNode = {

export async function getNavbarTree() {
const pages = await getNavbarPages();

const root: NavbarNode = { name: 'root', children: new Map(), url: '/', id: '_' };

for (const page of pages) {
if (!page.slug || !page.name) continue;

const parts = page.name.split('/').filter(Boolean);

let parent = root;

for (const part of parts) {
if (!parent.children.has(part))
parent.children.set(part, { name: part, parent, children: new Map(), url: '', id: String(page.id) });

parent = parent.children.get(part)!;
}

parent.url = page.slug;
parent.name = parts.at(-1) || '';
}
const root: NavbarNode = { name: 'root', id: 'root', url: '', children: new Map() };

pages.forEach((item) => {
const parts = item.name!.split('/');
let current = root;

parts.forEach((part, index) => {
if (!current.children.has(part)) {
const nodeId = `synthetic:${Math.random().toString(36).substring(2, 9)}`;
const newNode: NavbarNode = {
url: '',
id: nodeId,
name: part,
parent: current,
children: new Map(),
};

current.children.set(part, newNode);
}

current = current.children.get(part)!;

if (index === parts.length - 1) {
current.url = item.slug!;
current.id = String(item.id);
}
});
});

return root;
}

0 comments on commit 94197af

Please sign in to comment.