Harden CMS security, fix SEO/a11y gaps, and fill in missing article images
CI / build (push) Has been cancelled
CI / build (push) Has been cancelled
Server: refuse to start in production with the default admin password, drop SVG from the upload allow-list (stored-XSS risk), add baseline security headers, make the login rate limiter proxy-aware via TRUST_PROXY, and auto-load .env.local/.env in dev. Admin: sanitise post bodies on content import/snapshot restore (previously bypassed sanitiseBody), confirm before discarding a draft, drop back to the login screen on a mid-session 401 instead of a stuck error, add hero-image alt text and a title/excerpt search to the articles panel. Site: replace the soft-404-to-homepage fallback with a real noindex 404 page, add a focus trap/Escape handling/aria-modal to the enquiry modal, aria-expanded on the mobile nav toggle, ItemList/breadcrumb structured data for the newsroom and articles, and wire sitemap generation into the build so it can't go stale. Extract the duplicated NewsGrid/ArticlePage card markup into a shared PostCard component. Content: 13 of 18 seed articles shipped with no hero image (one pointed at a dead WordPress URL); the live blackdice.ai site turned out to still be the old blackdice-studio.html export, so recovering the originals wasn't feasible. Filled the gap with freely-licensed Unsplash placeholders, credited in the author field, until real photography is ready. Also adds a Gitea Actions CI workflow (typecheck + build). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import SiteApp from '../../site/SiteApp'
|
||||
import { checkSession, fileToOptimisedDataUrl, getToken, login, setToken, uploadAsset } from '../api'
|
||||
import { checkSession, fileToOptimisedDataUrl, getToken, login, SESSION_EXPIRED_EVENT, setToken, uploadAsset } from '../api'
|
||||
import { useDraft } from './useDraft'
|
||||
import { useInlineEditor } from './useInlineEditor'
|
||||
import { originals } from './originals'
|
||||
@@ -34,6 +34,7 @@ const TABS: { id: Tab; label: string }[] = [
|
||||
export default function AdminApp() {
|
||||
const [authed, setAuthed] = useState(Boolean(getToken()))
|
||||
const [checking, setChecking] = useState(Boolean(getToken()))
|
||||
const [sessionExpired, setSessionExpired] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) return
|
||||
@@ -46,7 +47,30 @@ export default function AdminApp() {
|
||||
.finally(() => setChecking(false))
|
||||
}, [])
|
||||
|
||||
if (!authed) return <LoginScreen onSignedIn={() => setAuthed(true)} busy={checking} />
|
||||
// A publish/upload/etc. can 401 mid-session if the token expires or is
|
||||
// revoked — drop back to the login screen instead of stranding the editor
|
||||
// on a raw "Not signed in" error with no way forward.
|
||||
useEffect(() => {
|
||||
const onExpired = () => {
|
||||
setAuthed(false)
|
||||
setSessionExpired(true)
|
||||
}
|
||||
window.addEventListener(SESSION_EXPIRED_EVENT, onExpired)
|
||||
return () => window.removeEventListener(SESSION_EXPIRED_EVENT, onExpired)
|
||||
}, [])
|
||||
|
||||
if (!authed) {
|
||||
return (
|
||||
<LoginScreen
|
||||
onSignedIn={() => {
|
||||
setSessionExpired(false)
|
||||
setAuthed(true)
|
||||
}}
|
||||
busy={checking}
|
||||
expired={sessionExpired}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return <Studio onSignOut={() => {
|
||||
setToken('')
|
||||
setAuthed(false)
|
||||
@@ -54,7 +78,7 @@ export default function AdminApp() {
|
||||
}
|
||||
|
||||
// ── Sign in ────────────────────────────────────────────────────────────────────
|
||||
function LoginScreen({ onSignedIn, busy }: { onSignedIn: () => void; busy: boolean }) {
|
||||
function LoginScreen({ onSignedIn, busy, expired = false }: { onSignedIn: () => void; busy: boolean; expired?: boolean }) {
|
||||
const [password, setPassword] = useState('')
|
||||
const [error, setError] = useState('')
|
||||
const [working, setWorking] = useState(false)
|
||||
@@ -82,6 +106,7 @@ function LoginScreen({ onSignedIn, busy }: { onSignedIn: () => void; busy: boole
|
||||
<form className="bdcms-login-box" onSubmit={submit}>
|
||||
<h1>BlackDice Studio</h1>
|
||||
<p>Sign in to edit the website, publish articles and manage the product demos.</p>
|
||||
{expired ? <p className="bdcms-err">Your session expired. Sign in again to continue.</p> : null}
|
||||
<div className="bdcms-field">
|
||||
<label>PASSWORD</label>
|
||||
<input
|
||||
@@ -145,7 +170,7 @@ function Studio({ onSignOut }: { onSignOut: () => void }) {
|
||||
pendingImage.current = null
|
||||
if (!file || !id) return
|
||||
if (!/^image\//.test(file.type)) {
|
||||
flash('Choose an image file (PNG, JPG, SVG or WebP).')
|
||||
flash('Choose an image file (PNG, JPG, GIF or WebP).')
|
||||
return
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -2,7 +2,16 @@ import { useEffect, useRef, useState } from 'react'
|
||||
import type { Post, SiteContent } from '../types'
|
||||
import { getVersion, listVersions } from '../api'
|
||||
import { resolveContent } from '../store'
|
||||
import { slugify } from '../sanitise'
|
||||
import { sanitiseBody, slugify } from '../sanitise'
|
||||
|
||||
// A version snapshot or an imported content file was written by *some* prior
|
||||
// publish, possibly by an older build with looser sanitisation. Re-sanitising
|
||||
// on the way back in is idempotent for already-clean bodies and closes off any
|
||||
// stored-XSS route through a crafted "content file" or stale studio draft.
|
||||
const sanitisePosts = (content: SiteContent): SiteContent => ({
|
||||
...content,
|
||||
posts: content.posts.map((p) => ({ ...p, body: sanitiseBody(p.body) })),
|
||||
})
|
||||
|
||||
interface Props {
|
||||
draft: SiteContent
|
||||
@@ -33,7 +42,7 @@ export default function HistoryPanel({ draft, published, replace, discard, toast
|
||||
if (!window.confirm(`Load the snapshot from ${label(name)} into the editor? Nothing goes live until you publish.`)) return
|
||||
try {
|
||||
const doc = await getVersion(name)
|
||||
replace(await resolveContent(doc), `SNAPSHOT ${label(name)} LOADED`)
|
||||
replace(sanitisePosts(await resolveContent(doc)), `SNAPSHOT ${label(name)} LOADED`)
|
||||
toast('Snapshot loaded into the editor. Review it, then publish.')
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Could not load that snapshot.')
|
||||
@@ -58,7 +67,7 @@ export default function HistoryPanel({ draft, published, replace, discard, toast
|
||||
try {
|
||||
const parsed = JSON.parse(await file.text())
|
||||
if (parsed.format === 'blackdice-react-content') {
|
||||
replace(await resolveContent(parsed), 'CONTENT FILE IMPORTED')
|
||||
replace(sanitisePosts(await resolveContent(parsed)), 'CONTENT FILE IMPORTED')
|
||||
toast('Content imported into the editor.')
|
||||
return
|
||||
}
|
||||
@@ -73,7 +82,7 @@ export default function HistoryPanel({ draft, published, replace, discard, toast
|
||||
author: p.author || 'BlackDice Cyber',
|
||||
excerpt: p.excerpt || '',
|
||||
hero: p.hero || '',
|
||||
body: p.body || '',
|
||||
body: sanitiseBody(p.body || ''),
|
||||
status: 'published',
|
||||
updatedAt: new Date().toISOString(),
|
||||
})) as Post[]
|
||||
@@ -105,7 +114,11 @@ export default function HistoryPanel({ draft, published, replace, discard, toast
|
||||
? `Last published ${new Date(published.savedAt).toLocaleString()}.`
|
||||
: 'Nothing has been published yet — the site is showing the content it shipped with.'}
|
||||
</p>
|
||||
<button className="bdcms-btn" onClick={discard}>
|
||||
<button
|
||||
className="bdcms-btn"
|
||||
onClick={() => {
|
||||
if (window.confirm('Discard all unpublished edits and reload exactly what is live? This cannot be undone.')) discard()
|
||||
}}>
|
||||
Discard my draft
|
||||
<small>Throw away local edits and show exactly what is live</small>
|
||||
</button>
|
||||
|
||||
@@ -25,6 +25,7 @@ const uniqueSlug = (posts: Post[], base: string, ignoreId: string) => {
|
||||
/** Blogs, news, press releases and event write-ups — the whole post library. */
|
||||
export default function PostsPanel({ draft, update, selected, onSelect, toast }: Props) {
|
||||
const [filter, setFilter] = useState<PostCategory | 'all'>('all')
|
||||
const [search, setSearch] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const heroRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
@@ -32,7 +33,12 @@ export default function PostsPanel({ draft, update, selected, onSelect, toast }:
|
||||
() => draft.posts.slice().sort((a, b) => (a.date < b.date ? 1 : a.date > b.date ? -1 : 0)),
|
||||
[draft.posts],
|
||||
)
|
||||
const shown = filter === 'all' ? posts : posts.filter((p) => p.category === filter)
|
||||
const shown = useMemo(() => {
|
||||
const byCategory = filter === 'all' ? posts : posts.filter((p) => p.category === filter)
|
||||
const q = search.trim().toLowerCase()
|
||||
if (!q) return byCategory
|
||||
return byCategory.filter((p) => p.title.toLowerCase().includes(q) || p.excerpt.toLowerCase().includes(q))
|
||||
}, [posts, filter, search])
|
||||
const post = posts.find((p) => p.slug === selected) || null
|
||||
|
||||
const patch = (id: string, changes: Partial<Post>) =>
|
||||
@@ -110,6 +116,13 @@ export default function PostsPanel({ draft, update, selected, onSelect, toast }:
|
||||
</button>
|
||||
|
||||
<div className="bdcms-h">LIBRARY · {posts.length} ARTICLES</div>
|
||||
<input
|
||||
className="bdcms-inp"
|
||||
style={{ marginBottom: 8 }}
|
||||
placeholder="Search by title or excerpt…"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
<div className="bdcms-tabs" style={{ padding: 0, border: 'none', marginBottom: 8 }}>
|
||||
{[{ id: 'all', label: 'All' }, ...POST_CATEGORIES].map((cat) => (
|
||||
<button
|
||||
@@ -259,6 +272,15 @@ export default function PostsPanel({ draft, update, selected, onSelect, toast }:
|
||||
value={post.hero}
|
||||
onChange={(e) => patch(post.id, { hero: e.target.value.trim() })}
|
||||
/>
|
||||
{post.hero ? (
|
||||
<input
|
||||
className="bdcms-inp"
|
||||
style={{ marginTop: 8 }}
|
||||
placeholder={`Alt text — describe the image (defaults to "${post.title}")`}
|
||||
value={post.heroAlt || ''}
|
||||
onChange={(e) => patch(post.id, { heroAlt: e.target.value })}
|
||||
/>
|
||||
) : null}
|
||||
<input
|
||||
ref={heroRef}
|
||||
type="file"
|
||||
|
||||
+17
-6
@@ -21,18 +21,30 @@ export const setToken = (token: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatched whenever an authenticated request comes back 401 — the token
|
||||
// expired or was revoked mid-session. AdminApp listens for this to drop back
|
||||
// to the login screen instead of leaving the editor showing a raw error.
|
||||
export const SESSION_EXPIRED_EVENT = 'bd-session-expired'
|
||||
|
||||
async function request<T>(url: string, init: RequestInit = {}): Promise<T> {
|
||||
const hadToken = Boolean(getToken())
|
||||
const res = await fetch(url, {
|
||||
...init,
|
||||
headers: {
|
||||
...(init.body ? { 'Content-Type': 'application/json' } : {}),
|
||||
...(getToken() ? { Authorization: `Bearer ${getToken()}` } : {}),
|
||||
...(hadToken ? { Authorization: `Bearer ${getToken()}` } : {}),
|
||||
...init.headers,
|
||||
},
|
||||
})
|
||||
const text = await res.text()
|
||||
const data = text ? JSON.parse(text) : {}
|
||||
if (!res.ok) throw Object.assign(new Error(data.error || `${res.status} ${res.statusText}`), { status: res.status })
|
||||
if (!res.ok) {
|
||||
if (res.status === 401 && hadToken && url !== '/api/login') {
|
||||
setToken('')
|
||||
window.dispatchEvent(new Event(SESSION_EXPIRED_EVENT))
|
||||
}
|
||||
throw Object.assign(new Error(data.error || `${res.status} ${res.statusText}`), { status: res.status })
|
||||
}
|
||||
return data as T
|
||||
}
|
||||
|
||||
@@ -94,10 +106,9 @@ export function fileToOptimisedDataUrl(file: File, maxWidth = 1920, quality = 0.
|
||||
return
|
||||
}
|
||||
if (file.type === 'image/svg+xml') {
|
||||
const reader = new FileReader()
|
||||
reader.onload = () => resolve(String(reader.result))
|
||||
reader.onerror = () => reject(new Error('Could not read that file.'))
|
||||
reader.readAsDataURL(file)
|
||||
// The server rejects SVG uploads (they can carry <script>) — fail fast
|
||||
// with a clear message instead of letting it round-trip to a 415.
|
||||
reject(new Error('SVG images are not supported. Use PNG, JPG, WebP or GIF.'))
|
||||
return
|
||||
}
|
||||
const url = URL.createObjectURL(file)
|
||||
|
||||
File diff suppressed because one or more lines are too long
+35
-2
@@ -65,8 +65,9 @@ export function applyMeta({ title, description, path, image, type = 'website', s
|
||||
metaByName('twitter:image').setAttribute('content', absImage)
|
||||
}
|
||||
|
||||
/** Structured data for the current view; replaces any previous block. */
|
||||
export function applyJsonLd(data: object | null) {
|
||||
/** Structured data for the current view; replaces any previous block. Accepts
|
||||
* one object or several (rendered as a JSON-LD array in a single script tag). */
|
||||
export function applyJsonLd(data: object | object[] | null) {
|
||||
const id = 'bd-jsonld'
|
||||
document.getElementById(id)?.remove()
|
||||
if (!data) return
|
||||
@@ -77,6 +78,38 @@ export function applyJsonLd(data: object | null) {
|
||||
document.head.appendChild(script)
|
||||
}
|
||||
|
||||
/** Home › Section › Page, for rich-result breadcrumbs. */
|
||||
export const breadcrumbJsonLd = (items: { name: string; url: string }[]) => ({
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: items.map((item, i) => ({
|
||||
'@type': 'ListItem',
|
||||
position: i + 1,
|
||||
name: item.name,
|
||||
item: item.url,
|
||||
})),
|
||||
})
|
||||
|
||||
/** The newsroom listing (/news) as an indexable collection of articles. */
|
||||
export const newsroomJsonLd = (
|
||||
posts: { title: string; slug: string; date: string }[],
|
||||
siteUrl = DEFAULT_SITE_URL,
|
||||
) => ({
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'CollectionPage',
|
||||
name: 'Newsroom | BlackDice Cyber',
|
||||
url: `${siteUrl}/news`,
|
||||
mainEntity: {
|
||||
'@type': 'ItemList',
|
||||
itemListElement: posts.map((post, i) => ({
|
||||
'@type': 'ListItem',
|
||||
position: i + 1,
|
||||
url: `${siteUrl}/blog/${post.slug}`,
|
||||
name: post.title,
|
||||
})),
|
||||
},
|
||||
})
|
||||
|
||||
export const organisationJsonLd = (siteUrl = DEFAULT_SITE_URL) => ({
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'Organization',
|
||||
|
||||
@@ -18,6 +18,8 @@ export interface Post {
|
||||
excerpt: string
|
||||
/** URL of the hero image ('' for none). */
|
||||
hero: string
|
||||
/** Alt text for the hero image. Falls back to the title when empty. */
|
||||
heroAlt?: string
|
||||
/** Article body as sanitised HTML. */
|
||||
body: string
|
||||
status: PostStatus
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
{/* Legacy hash-era and mistyped URLs still land on a working page. */}
|
||||
<Route path="/blog" element={<SiteApp pageId="p7" />} />
|
||||
<Route path="/blog.html" element={<SiteApp pageId="p7" />} />
|
||||
<Route path="*" element={<SiteApp pageId="p1" />} />
|
||||
<Route path="*" element={<SiteApp notFound />} />
|
||||
</Routes>
|
||||
</ContentProvider>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { useEffect } from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useContent } from '../cms/store'
|
||||
import { applyJsonLd, applyMeta } from '../cms/seo'
|
||||
|
||||
/**
|
||||
* Rendered for any URL that doesn't match a real page, article or demo route.
|
||||
* A dedicated noindex page (rather than silently showing the homepage) keeps
|
||||
* mistyped/stale links from being indexed as duplicate homepage content.
|
||||
*/
|
||||
export default function NotFoundPage({ suppressMeta = false }: { suppressMeta?: boolean }) {
|
||||
const content = useContent()
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
|
||||
useEffect(() => {
|
||||
if (suppressMeta) return
|
||||
applyMeta({
|
||||
title: 'Page not found | BlackDice Cyber',
|
||||
description: 'The page you are looking for does not exist.',
|
||||
path: location.pathname,
|
||||
siteUrl: content.settings.siteUrl,
|
||||
robots: 'noindex, follow',
|
||||
})
|
||||
applyJsonLd(null)
|
||||
}, [suppressMeta, location.pathname, content.settings.siteUrl])
|
||||
|
||||
return (
|
||||
<section className="bd-sect t">
|
||||
<div className="bd-si" style={{ maxWidth: 720 }}>
|
||||
<span className="ey">404</span>
|
||||
<h1 className="h1" style={{ fontSize: 'clamp(28px,3vw,40px)', marginBottom: 16 }}>
|
||||
We can't find that page.
|
||||
</h1>
|
||||
<p style={{ color: 'var(--t2)', fontSize: 16, marginBottom: 24 }}>
|
||||
There's nothing at <code>{location.pathname}</code>. It may have been moved or the link may be out of date.
|
||||
</p>
|
||||
<div className="btn-row">
|
||||
<button className="btn-p" onClick={() => navigate('/')}>
|
||||
Back to the homepage
|
||||
</button>
|
||||
<button className="btn-g" onClick={() => navigate('/news')}>
|
||||
Visit the newsroom
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
+36
-9
@@ -12,11 +12,12 @@ import { configureForms, initSite, setSiteNavigator, showPage, teardownSite } fr
|
||||
import ThreatDemosSlider from '../demo/threats/ThreatDemosSlider'
|
||||
import NewsGrid from './blog/NewsGrid'
|
||||
import ArticlePage from './blog/ArticlePage'
|
||||
import NotFoundPage from './NotFoundPage'
|
||||
import DemoSection from './demos/DemoSection'
|
||||
import DemoPlayer from './demos/DemoPlayer'
|
||||
import { applyContent, useContent } from '../cms/store'
|
||||
import { applyContent, publishedPosts, useContent } from '../cms/store'
|
||||
import { pageById } from '../cms/pages'
|
||||
import { applyJsonLd, applyMeta, organisationJsonLd } from '../cms/seo'
|
||||
import { applyJsonLd, applyMeta, breadcrumbJsonLd, newsroomJsonLd, organisationJsonLd } from '../cms/seo'
|
||||
import { submitLead } from '../cms/api'
|
||||
import type { SiteContent } from '../cms/types'
|
||||
|
||||
@@ -33,17 +34,25 @@ const ISLANDS = [
|
||||
] as const
|
||||
|
||||
export interface SiteAppProps {
|
||||
/** Page to show (p1…p12). Ignored when `articleSlug` is set. */
|
||||
/** Page to show (p1…p12). Ignored when `articleSlug` or `notFound` is set. */
|
||||
pageId?: string
|
||||
/** Renders the article view at /blog/<slug>. */
|
||||
articleSlug?: string
|
||||
/** Renders a noindex 404 instead of a real page — for unmatched routes. */
|
||||
notFound?: boolean
|
||||
/** Admin preview: content comes from the editor's draft, not the published doc. */
|
||||
previewContent?: SiteContent
|
||||
/** Suppress meta/JSON-LD writes (the admin owns the document head). */
|
||||
suppressMeta?: boolean
|
||||
}
|
||||
|
||||
export default function SiteApp({ pageId = 'p1', articleSlug, previewContent, suppressMeta = false }: SiteAppProps) {
|
||||
export default function SiteApp({
|
||||
pageId = 'p1',
|
||||
articleSlug,
|
||||
notFound = false,
|
||||
previewContent,
|
||||
suppressMeta = false,
|
||||
}: SiteAppProps) {
|
||||
const navigate = useNavigate()
|
||||
const wrapRef = useRef<HTMLDivElement>(null)
|
||||
const publishedContent = useContent()
|
||||
@@ -77,7 +86,7 @@ export default function SiteApp({ pageId = 'p1', articleSlug, previewContent, su
|
||||
|
||||
// Boot the ported controller and hand it the router.
|
||||
setSiteNavigator((path: string) => navigate(path))
|
||||
initSite(articleSlug ? 'article' : pageId)
|
||||
initSite(articleSlug || notFound ? 'article' : pageId)
|
||||
|
||||
// Reliably wire the "Talk to us" CTAs to open the Request-a-demonstration
|
||||
// modal (in case the inline onclick handler doesn't bind in some contexts).
|
||||
@@ -137,13 +146,14 @@ export default function SiteApp({ pageId = 'p1', articleSlug, previewContent, su
|
||||
// ── Route → page ────────────────────────────────────────────────────────────
|
||||
useEffect(() => {
|
||||
if (articleSlug) showPage('article', 'p7')
|
||||
else if (notFound) showPage('article') // no nav item highlighted for a generic 404
|
||||
else showPage(pageId)
|
||||
}, [pageId, articleSlug])
|
||||
}, [pageId, articleSlug, notFound])
|
||||
|
||||
// ── Metadata ────────────────────────────────────────────────────────────────
|
||||
const seo = useMemo(() => content.seo[pageId], [content, pageId])
|
||||
useEffect(() => {
|
||||
if (suppressMeta || articleSlug) return // ArticlePage owns article metadata
|
||||
if (suppressMeta || articleSlug || notFound) return // ArticlePage/NotFoundPage own their own metadata
|
||||
const page = pageById(pageId)
|
||||
if (!page || !seo) return
|
||||
applyMeta({
|
||||
@@ -154,8 +164,21 @@ export default function SiteApp({ pageId = 'p1', articleSlug, previewContent, su
|
||||
siteUrl: content.settings.siteUrl,
|
||||
robots: page.indexable ? 'index, follow' : 'noindex, follow',
|
||||
})
|
||||
applyJsonLd(pageId === 'p1' ? organisationJsonLd(content.settings.siteUrl) : null)
|
||||
}, [pageId, seo, articleSlug, suppressMeta, content.settings.siteUrl])
|
||||
if (pageId === 'p1') {
|
||||
applyJsonLd(organisationJsonLd(content.settings.siteUrl))
|
||||
} else if (pageId === 'p7') {
|
||||
const siteUrl = content.settings.siteUrl
|
||||
applyJsonLd([
|
||||
breadcrumbJsonLd([
|
||||
{ name: 'Home', url: siteUrl },
|
||||
{ name: 'News', url: `${siteUrl}/news` },
|
||||
]),
|
||||
newsroomJsonLd(publishedPosts(content), siteUrl),
|
||||
])
|
||||
} else {
|
||||
applyJsonLd(null)
|
||||
}
|
||||
}, [pageId, seo, articleSlug, notFound, suppressMeta, content])
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -194,6 +217,10 @@ export default function SiteApp({ pageId = 'p1', articleSlug, previewContent, su
|
||||
<ArticlePage slug={articleSlug} suppressMeta={suppressMeta} content={content} />,
|
||||
mounts['pg-article'],
|
||||
)}
|
||||
|
||||
{notFound &&
|
||||
mounts['pg-article'] &&
|
||||
createPortal(<NotFoundPage suppressMeta={suppressMeta} />, mounts['pg-article'])}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
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 { applyJsonLd, applyMeta, articleJsonLd, breadcrumbJsonLd } from '../../cms/seo'
|
||||
import { categoryMeta, splitAuthor } from './blogHelpers'
|
||||
import PostCard from './PostCard'
|
||||
import type { Post, SiteContent } from '../../cms/types'
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,18 @@ export default function ArticlePage({
|
||||
siteUrl: content.settings.siteUrl,
|
||||
robots: post.status === 'draft' ? 'noindex, nofollow' : 'index, follow',
|
||||
})
|
||||
applyJsonLd(post.status === 'draft' ? null : articleJsonLd(post, content.settings.siteUrl))
|
||||
applyJsonLd(
|
||||
post.status === 'draft'
|
||||
? null
|
||||
: [
|
||||
breadcrumbJsonLd([
|
||||
{ name: 'Home', url: content.settings.siteUrl },
|
||||
{ name: 'News', url: `${content.settings.siteUrl}/news` },
|
||||
{ name: post.title, url: `${content.settings.siteUrl}/blog/${post.slug}` },
|
||||
]),
|
||||
articleJsonLd(post, content.settings.siteUrl),
|
||||
],
|
||||
)
|
||||
}, [post, slug, content.settings.siteUrl, suppressMeta])
|
||||
|
||||
if (!post) {
|
||||
@@ -104,7 +116,7 @@ export default function ArticlePage({
|
||||
<div className="bd-si bd-article-wrap">
|
||||
{post.hero ? (
|
||||
<figure className="bd-article-hero-img">
|
||||
<img src={post.hero} alt={post.title} />
|
||||
<img src={post.hero} alt={post.heroAlt || post.title} />
|
||||
{credit ? <figcaption>{credit}</figcaption> : null}
|
||||
</figure>
|
||||
) : null}
|
||||
@@ -121,15 +133,7 @@ export default function ArticlePage({
|
||||
</div>
|
||||
<div className="news-grid">
|
||||
{related.map((other) => (
|
||||
<article key={other.id} className="news-card bd-news-card" onClick={() => navigate(`/blog/${other.slug}`)}>
|
||||
<span className={`news-tag ${categoryMeta(other.category).cls}`}>
|
||||
{categoryMeta(other.category).label.toUpperCase()}
|
||||
</span>
|
||||
<h3>{other.title}</h3>
|
||||
<p className="bd-news-meta">{formatPostDate(other.date)}</p>
|
||||
<p>{other.excerpt}</p>
|
||||
<span className="bd-news-more">Read more →</span>
|
||||
</article>
|
||||
<PostCard key={other.id} post={other} onOpen={(p) => navigate(`/blog/${p.slug}`)} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,48 +1,8 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { POST_CATEGORIES, type Post, type PostCategory, type SiteContent } from '../../cms/types'
|
||||
import { formatPostDate, publishedPosts, useContent } from '../../cms/store'
|
||||
|
||||
export const categoryMeta = (id: string) => POST_CATEGORIES.find((c) => c.id === id) || POST_CATEGORIES[0]
|
||||
|
||||
/** Authors are stored as "Paul Hague (Image by … on Unsplash)" — split the credit out. */
|
||||
export function splitAuthor(author: string) {
|
||||
const match = /^(.*?)\s*\(([^)]*)\)\s*$/.exec(author || '')
|
||||
return match ? { name: match[1].trim(), credit: match[2].trim() } : { name: (author || '').trim(), credit: '' }
|
||||
}
|
||||
|
||||
function Card({ post, onOpen }: { post: Post; onOpen: (post: Post) => void }) {
|
||||
const cat = categoryMeta(post.category)
|
||||
const { name } = splitAuthor(post.author)
|
||||
return (
|
||||
<article
|
||||
className="news-card bd-news-card"
|
||||
role="link"
|
||||
tabIndex={0}
|
||||
onClick={() => onOpen(post)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
onOpen(post)
|
||||
}
|
||||
}}>
|
||||
{post.hero ? (
|
||||
<div className="bd-news-thumb">
|
||||
<img src={post.hero} alt="" loading="lazy" />
|
||||
</div>
|
||||
) : null}
|
||||
<span className={`news-tag ${cat.cls}`}>{cat.label.toUpperCase()}</span>
|
||||
{post.status === 'draft' ? <span className="bd-news-draft">DRAFT</span> : null}
|
||||
<h3>{post.title}</h3>
|
||||
<p className="bd-news-meta">
|
||||
{formatPostDate(post.date)}
|
||||
{name ? ` · ${name}` : ''}
|
||||
</p>
|
||||
<p>{post.excerpt}</p>
|
||||
<span className="bd-news-more">Read more →</span>
|
||||
</article>
|
||||
)
|
||||
}
|
||||
import { publishedPosts, useContent } from '../../cms/store'
|
||||
import PostCard from './PostCard'
|
||||
|
||||
/**
|
||||
* The newsroom grid (/news) and the home page's latest-three strip. Both read the
|
||||
@@ -118,7 +78,7 @@ export default function NewsGrid({
|
||||
|
||||
<div className="news-grid">
|
||||
{posts.map((post) => (
|
||||
<Card key={post.id} post={post} onOpen={open} />
|
||||
<PostCard key={post.id} post={post} onOpen={open} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { formatPostDate } from '../../cms/store'
|
||||
import type { Post } from '../../cms/types'
|
||||
import { categoryMeta, splitAuthor } from './blogHelpers'
|
||||
|
||||
/** A single card in the newsroom grid, the home strip, and an article's "keep reading" list. */
|
||||
export default function PostCard({ post, onOpen }: { post: Post; onOpen: (post: Post) => void }) {
|
||||
const cat = categoryMeta(post.category)
|
||||
const { name } = splitAuthor(post.author)
|
||||
return (
|
||||
<article
|
||||
className="news-card bd-news-card"
|
||||
role="link"
|
||||
tabIndex={0}
|
||||
onClick={() => onOpen(post)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
onOpen(post)
|
||||
}
|
||||
}}>
|
||||
{post.hero ? (
|
||||
<div className="bd-news-thumb">
|
||||
<img src={post.hero} alt={post.heroAlt || post.title} loading="lazy" />
|
||||
</div>
|
||||
) : null}
|
||||
<span className={`news-tag ${cat.cls}`}>{cat.label.toUpperCase()}</span>
|
||||
{post.status === 'draft' ? <span className="bd-news-draft">DRAFT</span> : null}
|
||||
<h3>{post.title}</h3>
|
||||
<p className="bd-news-meta">
|
||||
{formatPostDate(post.date)}
|
||||
{name ? ` · ${name}` : ''}
|
||||
</p>
|
||||
<p>{post.excerpt}</p>
|
||||
<span className="bd-news-more">Read more →</span>
|
||||
</article>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { POST_CATEGORIES } from '../../cms/types'
|
||||
|
||||
export const categoryMeta = (id: string) => POST_CATEGORIES.find((c) => c.id === id) || POST_CATEGORIES[0]
|
||||
|
||||
/** Authors are stored as "Paul Hague (Image by … on Unsplash)" — split the credit out. */
|
||||
export function splitAuthor(author: string) {
|
||||
const match = /^(.*?)\s*\(([^)]*)\)\s*$/.exec(author || '')
|
||||
return match ? { name: match[1].trim(), credit: match[2].trim() } : { name: (author || '').trim(), credit: '' }
|
||||
}
|
||||
@@ -201,7 +201,10 @@ function goHome() {
|
||||
function toggleMob() {
|
||||
var mob = document.getElementById("mob-nav");
|
||||
if (!mob) return;
|
||||
mob.style.display = mob.style.display === "none" ? "block" : "none";
|
||||
var opening = mob.style.display === "none";
|
||||
mob.style.display = opening ? "block" : "none";
|
||||
var ham = document.querySelector(".bd-ham");
|
||||
if (ham) ham.setAttribute("aria-expanded", opening ? "true" : "false");
|
||||
}
|
||||
|
||||
// ── Scroll ─────────────────────────────────────────────────────────────────
|
||||
@@ -225,6 +228,40 @@ function scrollDown() {
|
||||
}
|
||||
|
||||
// ── Demo modal ─────────────────────────────────────────────────────────────
|
||||
// A modal needs to trap focus and close on Escape to be usable by keyboard
|
||||
// and screen-reader visitors — otherwise Tab can walk out into the hidden
|
||||
// page behind it, with no keyboard way back in or out.
|
||||
|
||||
var __bdModalLastFocus = null;
|
||||
|
||||
function __bdModalFocusables() {
|
||||
var box = document.querySelector("#modal-ov .modal-box");
|
||||
if (!box) return [];
|
||||
return Array.prototype.filter.call(
|
||||
box.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),
|
||||
function (el) { return !el.disabled && el.offsetParent !== null; },
|
||||
);
|
||||
}
|
||||
|
||||
function __bdModalKeydown(e) {
|
||||
if (e.key === "Escape" || e.key === "Esc") {
|
||||
e.preventDefault();
|
||||
closeDemo();
|
||||
return;
|
||||
}
|
||||
if (e.key !== "Tab") return;
|
||||
var focusables = __bdModalFocusables();
|
||||
if (!focusables.length) return;
|
||||
var first = focusables[0];
|
||||
var last = focusables[focusables.length - 1];
|
||||
if (e.shiftKey && document.activeElement === first) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
} else if (!e.shiftKey && document.activeElement === last) {
|
||||
e.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function showDemo() {
|
||||
var ov = document.getElementById("modal-ov");
|
||||
@@ -235,11 +272,19 @@ function showDemo() {
|
||||
if (form) form.style.display = "block";
|
||||
if (sent) sent.style.display = "none";
|
||||
if (err) err.style.display = "none";
|
||||
|
||||
__bdModalLastFocus = document.activeElement;
|
||||
document.addEventListener("keydown", __bdModalKeydown, true);
|
||||
var focusables = __bdModalFocusables();
|
||||
if (focusables.length) focusables[0].focus();
|
||||
}
|
||||
|
||||
function closeDemo() {
|
||||
var ov = document.getElementById("modal-ov");
|
||||
if (ov) ov.style.display = "none";
|
||||
document.removeEventListener("keydown", __bdModalKeydown, true);
|
||||
if (__bdModalLastFocus && typeof __bdModalLastFocus.focus === "function") __bdModalLastFocus.focus();
|
||||
__bdModalLastFocus = null;
|
||||
}
|
||||
|
||||
function closeBg(e) {
|
||||
@@ -457,4 +502,5 @@ export function initSite(startPage) {
|
||||
export function teardownSite() {
|
||||
window.removeEventListener('scroll', onScroll);
|
||||
if (__bdFeedTimer) { clearInterval(__bdFeedTimer); __bdFeedTimer = null; }
|
||||
document.removeEventListener('keydown', __bdModalKeydown, true);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</div>
|
||||
<button data-cms="c0012" class="bd-nl bd-nav-cta" onclick="showDemo()">Talk to us</button>
|
||||
</div>
|
||||
<button class="bd-ham" onclick="toggleMob()" aria-label="Menu"><span></span><span></span><span></span></button>
|
||||
<button class="bd-ham" onclick="toggleMob()" aria-label="Menu" aria-expanded="false" aria-controls="mob-nav"><span></span><span></span><span></span></button>
|
||||
</nav>
|
||||
|
||||
<!-- MOBILE NAV -->
|
||||
@@ -3968,7 +3968,7 @@
|
||||
|
||||
<!-- ═══ DEMO MODAL ═══ -->
|
||||
<div id="modal-ov" class="modal-ov" style="display:none" onclick="closeBg(event)">
|
||||
<div class="modal-box">
|
||||
<div class="modal-box" role="dialog" aria-modal="true" aria-label="Request a demonstration">
|
||||
<button data-cms="c0630" class="modal-x" onclick="closeDemo()">✕</button>
|
||||
<div id="modal-form" style="display:block">
|
||||
<span data-cms="c0631"
|
||||
|
||||
Reference in New Issue
Block a user