mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 03:53:37 -06:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import "./Breadcrumb.css";
|
||
import { useNoteContext } from "./react/hooks";
|
||
import NoteLink from "./react/NoteLink";
|
||
import { joinElements } from "./react/react_utils";
|
||
|
||
export default function Breadcrumb() {
|
||
const { noteContext } = useNoteContext();
|
||
const notePath = buildNotePaths(noteContext?.notePathArray);
|
||
|
||
return (
|
||
<div className="breadcrumb">
|
||
{joinElements(notePath.map(item => (
|
||
<BreadcrumbItem key={item} notePath={item} />
|
||
)), <> › </>)}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
function BreadcrumbItem({ notePath }: { notePath: string }) {
|
||
return (
|
||
<NoteLink
|
||
notePath={notePath}
|
||
noPreview
|
||
/>
|
||
)
|
||
}
|
||
|
||
function buildNotePaths(notePathArray: string[] | undefined) {
|
||
if (!notePathArray) return [];
|
||
|
||
let prefix = "";
|
||
const output: string[] = [];
|
||
for (const notePath of notePathArray.slice(0, notePathArray.length - 1)) {
|
||
output.push(`${prefix}${notePath}`);
|
||
prefix += `${notePath}/`;
|
||
}
|
||
return output;
|
||
}
|