import Link from "next/link"; import Markdown from "react-markdown"; import type { LearnVariant } from "@/lib/content/zhouyi"; function resolveLearnHref( href: string | undefined, variant: LearnVariant, ): string | undefined { if (!href) { return href; } if (href.startsWith("http://") || href.startsWith("https://")) { return href; } const base = variant === "traditional" ? "/learn" : "/learn/other"; if (href === "index.md" || href === "./index.md") { return base; } if (href === "other/index.md") { return "/learn/other"; } if (href.endsWith("/index.md")) { const mark = href.replace(/\/index\.md$/, "").replace(/^\.\//, ""); if (mark.startsWith("other/")) { const folder = mark.slice("other/".length); const num = folder.split(".")[0]; return `/learn/other/${num}`; } const num = mark.split(".")[0]; return `${base}/${num}`; } return href; } export default function MarkdownContent({ content, variant = "traditional", }: { content: string; variant?: LearnVariant; }) { return ( { const resolved = resolveLearnHref(href, variant); if (resolved?.startsWith("/")) { return ( {children} ); } return ( {children} ); }, img: ({ src, alt, ...props }) => { if (typeof src === "string" && !src.startsWith("http")) { return ( [{alt || "卦象图片"}] ); } return {alt}; }, }} > {content} ); }