import { Link, renderInlineMarkdown } from '@rspress/core/theme'; import './index.scss'; import type { Header } from '@rspress/core'; import { routePathToMdPath } from '@rspress/core/runtime'; import { FallbackHeading, SvgWrapper } from '@rspress/core/theme'; import { useMemo } from 'react'; import IconPlugin from './icons/plugin.svg'; function OverviewGroupMarkdown({ group }: { group: Group }) { const lines: string[] = []; if (group.name) { lines.push(`## ${group.name}`); lines.push(''); } for (const item of group.items) { const itemTitle = item.link ? `[${item.text}](${routePathToMdPath(item.link)})` : `**${item.text}**`; lines.push(`### ${itemTitle}`); lines.push(''); // Render headers as a list if (item.headers && item.headers.length > 0) { for (const header of item.headers) { const headerLink = item.link ? `[${header.text}](${routePathToMdPath(item.link)}#${header.id})` : header.text; lines.push(`- ${headerLink}`); } lines.push(''); } // Render custom items as a list if (item.items && item.items.length > 0) { for (const subItem of item.items) { const subItemLink = subItem.link ? `[${subItem.text}](${routePathToMdPath(subItem.link)})` : subItem.text; lines.push(`- ${subItemLink}`); } lines.push(''); } } return <>{lines.join('\n')}; } export interface GroupItem { text: string; link: string; headers?: Omit[]; // For customization items?: { text: string; link: string }[]; } export interface Group { name: string; items: GroupItem[]; } export const OverviewGroup = ({ group }: { group: Group }) => { if (import.meta.env.SSG_MD) { return ; } const { itemsWithContent, itemsWithoutContent } = useMemo(() => { // Separate items into those with content and those without const itemsWithContent = group.items.filter( item => (item.headers && item.headers.length > 0) || (item.items && item.items.length > 0), ); const itemsWithoutContent = group.items.filter( item => !(item.headers && item.headers.length > 0) && !(item.items && item.items.length > 0), ); return { itemsWithContent, itemsWithoutContent }; }, [group]); return ( <>
{/* Render items with content in the standard split layout */} {itemsWithContent.map(item => (
{item.link ? ( ) : ( )}
    {item.headers?.map(header => (
  • ))} {item.items?.map(({ link, text }) => { return (
  • ); })}
))} {/* Render items without content in a grid layout */} {itemsWithoutContent.length > 0 && (
{itemsWithoutContent.map(item => (
{item.link ? ( ) : ( )}
))}
)}
); };