import { useEffect, useMemo } from 'react' import { useNavigate } from 'react-router-dom' import { formatPostDate, publishedPosts, useContent } from '../../cms/store' import { applyJsonLd, applyMeta, articleJsonLd } from '../../cms/seo' import { categoryMeta, splitAuthor } from './NewsGrid' import type { Post, SiteContent } from '../../cms/types' /** * A single article at /blog/. Rendered into the #pg-article container inside * the site markup, so it inherits the real nav, footer and enquiry modal — and the * white-section rule that makes the body copy readable. */ export default function ArticlePage({ slug, suppressMeta = false, content: contentProp, }: { slug: string suppressMeta?: boolean /** Admin preview: use the editor's draft rather than the published context. */ content?: SiteContent }) { const publishedContent = useContent() const content = contentProp || publishedContent const navigate = useNavigate() // Drafts are reachable by direct link so they can be reviewed before going live, // but they never appear in listings or the sitemap. const post = useMemo(() => content.posts.find((p) => p.slug === slug), [content, slug]) const related = useMemo(() => { const others = publishedPosts(content).filter((p) => p.slug !== slug) const sameCategory = others.filter((p) => p.category === post?.category) return [...sameCategory, ...others.filter((p) => p.category !== post?.category)].slice(0, 3) }, [content, post, slug]) useEffect(() => { if (suppressMeta) return // the admin preview leaves the document head alone if (!post) { applyMeta({ title: 'Article not found | BlackDice Cyber', description: 'The article you are looking for is no longer available.', path: `/blog/${slug}`, siteUrl: content.settings.siteUrl, robots: 'noindex, follow', }) applyJsonLd(null) return } applyMeta({ title: post.metaTitle || `${post.title} | BlackDice Cyber`, description: post.metaDescription || post.excerpt, path: `/blog/${post.slug}`, image: post.hero || undefined, type: 'article', siteUrl: content.settings.siteUrl, robots: post.status === 'draft' ? 'noindex, nofollow' : 'index, follow', }) applyJsonLd(post.status === 'draft' ? null : articleJsonLd(post, content.settings.siteUrl)) }, [post, slug, content.settings.siteUrl, suppressMeta]) if (!post) { return (
NEWSROOM

That article has moved.

We could not find an article at /blog/{slug}. It may have been renamed or unpublished.

) } const cat = categoryMeta(post.category) const { name, credit } = splitAuthor(post.author) return ( <>
{cat.label.toUpperCase()} {post.status === 'draft' ? DRAFT — NOT PUBLISHED : null}

{post.title}

{formatPostDate(post.date)} {name ? ` · ${name}` : ''}

{post.hero ? (
{post.title} {credit ?
{credit}
: null}
) : null}
KEEP READING

More from BlackDice

{related.map((other) => (
navigate(`/blog/${other.slug}`)}> {categoryMeta(other.category).label.toUpperCase()}

{other.title}

{formatPostDate(other.date)}

{other.excerpt}

Read more →
))}

Want to see this working on your network? Talk to us.

Tell us about your subscriber base and we will show you the intelligence BlackDice surfaces from within your own infrastructure.

) } function ArticleShare({ post, siteUrl }: { post: Post; siteUrl: string }) { const url = `${siteUrl.replace(/\/+$/, '')}/blog/${post.slug}` const share = [ { label: 'LinkedIn', href: `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}` }, { label: 'X', href: `https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent(post.title)}` }, ] return (
SHARE THIS ARTICLE
{share.map((s) => ( {s.label} ))}
) }