--- import { Icon } from "astro-icon/components"; import DropdownItem from "@/components/common/DropdownItem.astro"; import DropdownPanel from "@/components/common/DropdownPanel.astro"; import { LinkPresets } from "@/constants/link-presets"; import { LinkPreset, type NavBarLink } from "@/types/config"; import { url } from "@/utils/url-utils"; interface Props { link: NavBarLink; class?: string; } const { link, class: className } = Astro.props; // 检查 link 是否存在 if (!link) { return null; } // 转换子菜单中的LinkPreset为NavBarLink const processedLink = { ...link, children: link.children ?.map((child: NavBarLink | LinkPreset): NavBarLink | null => { if (typeof child === "number") { // 检查 LinkPreset 是否存在于 LinkPresets 中 if (child in LinkPresets) { return LinkPresets[child as LinkPreset]; } return null; } return child; }) .filter((child): child is NavBarLink => child !== null), }; const hasChildren = processedLink.children && processedLink.children.length > 0; ---