Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

1.6 KB
Raw Blame
---
import { getCollection } from 'astro:content';
import type { Locale } from '../../i18n/i18n.constants';
import { useI18n } from '../../i18n/i18n';
import { cn } from '../../utils/cn';
import { getDocUrl, resolveDoc } from '../docs.models';
import type { DocsSection } from '../docs.types';

export type Props = {
  sections: DocsSection[];
  currentDocId?: string;
  locale: Locale;
};

const { sections, currentDocId, locale } = Astro.props;
const { t } = useI18n({ locale });
const docs = await getCollection('docs');
const augmentedSections = sections.map((section) => ({
  ...section,
  items: section.items.map((item) => ({
    ...item,
    title: resolveDoc({ docs, docId: item.docId, locale }).entry.data.title,
  })),
}));
---

{augmentedSections.map((section, index) => (
  <div class={cn('py-4', index !== 0 ? 'border-t' : '')}>
    <div class="text-13px font-medium mb-2 pl-4">{t(section.titleKey)}</div>
    <ul>
      {section.items.map((item) => (
        <li>
          <a
            href={getDocUrl({ docId: item.docId, locale })}
            aria-current={item.docId === currentDocId ? 'page' : undefined}
            class={cn(
              'text-sm text-muted-foreground hover:(bg-muted text-foreground) transition flex items-center min-h-11 md:min-h-0 px-4 rounded-lg py-1.2 my-1px',
              item.docId === currentDocId ? 'bg-muted text-foreground' : '',
            )}
          >
            {item.title}
          </a>
        </li>
      ))}
    </ul>
  </div>
))}

<style>
  a:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
  }
</style>