Capitalize categories in hierarchy
This commit is contained in:
@@ -10,8 +10,9 @@ interface Props {
|
|||||||
|
|
||||||
const { prefix, hierarchy: maybeHierarchy} = Astro.props;
|
const { prefix, hierarchy: maybeHierarchy} = Astro.props;
|
||||||
|
|
||||||
const hierarchy = maybeHierarchy ?? makeHierarchy((await getCollection('notes')).map(note => [note.id, note.data.title]));
|
const notes = await getCollection('notes');
|
||||||
|
|
||||||
|
const hierarchy = maybeHierarchy ?? makeHierarchy(notes.map(note => [note.id, note.data.title]));
|
||||||
|
|
||||||
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, '/');
|
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, '/');
|
||||||
|
|
||||||
|
|||||||
@@ -14,17 +14,18 @@ function addToHierarchy(
|
|||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tree[path[0]]) {
|
// Create a dummy node to start the loop since the Hierarchy root is not a node.
|
||||||
tree[path[0]] = { id: null, title: null, children: null };
|
let curr: HierarchyNode = { id: null, title: null, children: tree };
|
||||||
}
|
|
||||||
let curr = tree[path[0]];
|
for (const node of path) {
|
||||||
|
// Capitalize first letter
|
||||||
|
const nodeName = node.charAt(0).toUpperCase() + node.slice(1);
|
||||||
|
|
||||||
for (const node of path.slice(1)) {
|
|
||||||
curr.children ||= {};
|
curr.children ||= {};
|
||||||
if (!curr.children[node]) {
|
if (!curr.children[nodeName]) {
|
||||||
curr.children[node] = { id: null, title: null, children: null };
|
curr.children[nodeName] = { id: null, title: null, children: null };
|
||||||
}
|
}
|
||||||
curr = curr.children[node];
|
curr = curr.children[nodeName];
|
||||||
}
|
}
|
||||||
|
|
||||||
curr.id = noteId;
|
curr.id = noteId;
|
||||||
|
|||||||
Reference in New Issue
Block a user