import type { Heading } from '@vcarl/remark-headings'; import { useTranslations } from 'next-intl'; import { Fragment, useMemo } from 'react'; import type { FC } from 'react'; import Link from '@/components/Link'; import styles from './index.module.css'; type MetaBarProps = { items: Record; headings?: { items: Array; minDepth?: number; }; }; const MetaBar: FC = ({ items, headings }) => { const t = useTranslations(); // The default depth of headings to display in the table of contents. const { minDepth = 2, items: headingItems = [] } = headings || {}; const heading = useMemo( () => headingItems.filter(({ depth }) => depth >= minDepth && depth <= 4), [minDepth, headingItems] ); return (
{Object.entries(items) .filter(([, value]) => !!value) .map(([key, value]) => (
{t(key)}
{value}
))} {heading.length > 0 && ( <>
{t('components.metabar.tableOfContents')}
    {heading.map(head => (
  1. {head.value}
  2. ))}
)}
); }; export default MetaBar;