33 lines
913 B
TypeScript
33 lines
913 B
TypeScript
"use client";
|
|
|
|
import React, { useEffect } from 'react';
|
|
import { useCitations } from '@/components/context-citation';
|
|
import Link from 'next/link';
|
|
|
|
interface CiteProps {
|
|
bibtexKey: string;
|
|
}
|
|
|
|
export function Cite({ bibtexKey }: CiteProps) {
|
|
const { addCitedKey, getPublicationByKey } = useCitations();
|
|
const publication = getPublicationByKey(bibtexKey);
|
|
|
|
useEffect(() => {
|
|
addCitedKey(bibtexKey);
|
|
}, [bibtexKey, addCitedKey]);
|
|
|
|
if (!publication) {
|
|
return <span className="text-red-500">[Citation not found: {bibtexKey}]</span>;
|
|
}
|
|
|
|
const authorText = publication.authors.length > 2
|
|
? `${publication.authors[0].split(' ').pop()} et al.`
|
|
: publication.authors.map((author: string) => author.split(' ').pop()).join(' & ');
|
|
|
|
return (
|
|
<Link href={`/publications#${bibtexKey}`} className="text-primary hover:underline">
|
|
({authorText}, {publication.year})
|
|
</Link>
|
|
);
|
|
}
|