fumadocs-ui
Version:
The Radix UI version of Fumadocs UI
25 lines (24 loc) • 754 B
JavaScript
"use client";
import { useTreeContext } from "../contexts/tree.js";
//#region src/utils/use-footer-items.ts
const footerCache = /* @__PURE__ */ new WeakMap();
/**
* @returns a list of page tree items (linear), that you can obtain footer items
*/
function useFooterItems() {
const { root } = useTreeContext();
const cached = footerCache.get(root);
if (cached) return cached;
const list = [];
function onNode(node) {
if (node.type === "folder") {
if (node.index) onNode(node.index);
for (const child of node.children) onNode(child);
} else if (node.type === "page" && !node.external) list.push(node);
}
for (const child of root.children) onNode(child);
footerCache.set(root, list);
return list;
}
//#endregion
export { useFooterItems };