|
1 | 1 | import { Helmet } from 'react-helmet-async' |
2 | | -import { useMemo } from 'react' |
| 2 | +import { useMemo, useEffect } from 'react' |
3 | 3 | import { useContent } from '../context/ContentContext' |
| 4 | + |
4 | 5 | const FALLBACK_TITLE = 'Linux Tutorial - Lerne Linux Schritt für Schritt' |
5 | 6 | const FALLBACK_DESCRIPTION = 'Lerne Linux von Grund auf - Interaktiv, modern und praxisnah.' |
| 7 | + |
6 | 8 | const sanitize = (value) => { |
7 | 9 | if (typeof value !== 'string') { |
8 | 10 | return '' |
9 | 11 | } |
10 | 12 | return value.trim() |
11 | 13 | } |
| 14 | + |
12 | 15 | const GlobalSiteMeta = () => { |
13 | 16 | 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 | + |
22 | 21 | const title = sanitize(meta.title) || FALLBACK_TITLE |
23 | 22 | 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 | + |
24 | 31 | return ( |
25 | 32 | <Helmet> |
26 | 33 | <title>{title}</title> |
27 | 34 | {description && <meta name="description" content={description} />} |
| 35 | + |
28 | 36 | <meta property="og:title" content={title} /> |
29 | 37 | {description && <meta property="og:description" content={description} />} |
30 | 38 | <meta property="og:site_name" content={title} /> |
| 39 | + |
31 | 40 | {description && <meta name="twitter:description" content={description} />} |
32 | 41 | <meta name="twitter:title" content={title} /> |
33 | 42 | </Helmet> |
34 | 43 | ) |
35 | 44 | } |
| 45 | + |
36 | 46 | export default GlobalSiteMeta |
0 commit comments