Skip to content

Commit 95dc3ce

Browse files
committed
feat: add GlobalSiteMeta component to manage global SEO and social media metadata.
1 parent 12ccc45 commit 95dc3ce

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/components/GlobalSiteMeta.jsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
11
import { Helmet } from 'react-helmet-async'
2-
import { useMemo } from 'react'
2+
import { useMemo, useEffect } from 'react'
33
import { useContent } from '../context/ContentContext'
4+
45
const FALLBACK_TITLE = 'Linux Tutorial - Lerne Linux Schritt für Schritt'
56
const FALLBACK_DESCRIPTION = 'Lerne Linux von Grund auf - Interaktiv, modern und praxisnah.'
7+
68
const sanitize = (value) => {
79
if (typeof value !== 'string') {
810
return ''
911
}
1012
return value.trim()
1113
}
14+
1215
const GlobalSiteMeta = () => {
1316
const { getSiteMeta } = useContent()
14-
const meta = useMemo(() => {
15-
try {
16-
return typeof getSiteMeta === 'function' ? getSiteMeta() ?? {} : {}
17-
} catch (err) {
18-
console.warn('Failed to resolve site meta content:', err)
19-
return {}
20-
}
21-
}, [getSiteMeta])
17+
18+
// Get fresh meta data directly
19+
const meta = getSiteMeta() || {}
20+
2221
const title = sanitize(meta.title) || FALLBACK_TITLE
2322
const description = sanitize(meta.description) || FALLBACK_DESCRIPTION
23+
24+
// Force update document title directly as fallback
25+
useEffect(() => {
26+
if (title) {
27+
document.title = title
28+
}
29+
}, [title])
30+
2431
return (
2532
<Helmet>
2633
<title>{title}</title>
2734
{description && <meta name="description" content={description} />}
35+
2836
<meta property="og:title" content={title} />
2937
{description && <meta property="og:description" content={description} />}
3038
<meta property="og:site_name" content={title} />
39+
3140
{description && <meta name="twitter:description" content={description} />}
3241
<meta name="twitter:title" content={title} />
3342
</Helmet>
3443
)
3544
}
45+
3646
export default GlobalSiteMeta

0 commit comments

Comments
 (0)