aaronjy-me/src/components/Article/Article.jsx
2025-03-29 14:55:42 +00:00

41 lines
1.1 KiB
JavaScript

import { formatDate } from '@/lib/helpers'
import { NextSeo } from 'next-seo'
import Link from 'next/link'
import React, { useEffect } from 'react'
import 'highlight.js/styles/atom-one-dark.css'
import hljs from 'highlight.js'
function Article ({ attributes, html }) {
useEffect(() => {
hljs.highlightAll()
}, [attributes, html])
return (
<>
<h1>{attributes.title}</h1>
<article>
<NextSeo
title={attributes.title} description={attributes.desc} openGraph={
{
title: attributes.title,
description: attributes.desc,
type: 'article',
article: {
publishedTime: attributes.pubdate ?? null
}
}
}
/>
<div>
<Link href='./'>Back...</Link>
{attributes.pubdate && <p>{formatDate(attributes.pubdate)}</p>}
<div data-test='content' dangerouslySetInnerHTML={{ __html: html }} />
{attributes.tags && <p>Tags: {attributes.tags.join(', ')}</p>}
</div>
</article>
</>
)
}
export default Article