Files
blog_bricked/src/components/Content/Blockquote/index.tsx
2025-10-05 10:52:40 +02:00

71 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { marked } from 'marked';
import styles from './Blockquote.module.css';
interface BlockquoteProps {
quote: string;
attribution?: string;
source?: string;
url?: string;
}
export default function Blockquote({
quote,
attribution,
source,
url,
}: BlockquoteProps) {
const hasAttribution = !!attribution;
const hasSource = !!source;
const hasUrl = !!url;
const showFooter = hasSource || hasAttribution;
const attributionLinked = hasAttribution && hasUrl && !hasSource;
const sourceLinked = hasSource && hasUrl;
return (
<blockquote className={styles.blockquote}>
<div
className={styles.quote}
dangerouslySetInnerHTML={{ __html: marked.parse(quote) }}
/>
{showFooter && (
<footer className={styles.footer}>
{hasAttribution && (
<cite className={styles.attribution}>
{attributionLinked ? (
<a
href={url}
className={styles.link}
target="_blank"
rel="noopener noreferrer"
>
{attribution}
</a>
) : (
attribution
)}
</cite>
)}
{hasSource && (
<cite className={styles.source}>
{' '}
{sourceLinked ? (
<a
href={url}
className={styles.link}
target="_blank"
rel="noopener noreferrer"
>
{source}
</a>
) : (
source
)}
</cite>
)}
</footer>
)}
</blockquote>
);
}